﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using System.Collections;
//开发者:史麒亮
namespace LCWMS
{
    public partial class w_so019 : DockContent
    {
        private DataSet dscustomer = new DataSet();
        private DataSet ds_temp = new DataSet();
        private DataSet ds_temp_wave = new DataSet();
        DataSet ds_system_s;
        DataSet ds_system_send_no;
        private DataSet count = new DataSet();
        private DataSet i_ds_so_pack_header_s;
        DataSet i_ds_so_pack_detail;
        DataSet i_ds_so_pack_header;
        DataSet ds_s;
        DataSet ds;
        DataSet ds_wave;
        DataSet ds_wave_s;
        DataSet ds_address;
        //Rectangle _Rectangle;
        ComboBox cmb_send_type = new ComboBox();
        private BarcodeLib.Barcode b_bar = new BarcodeLib.Barcode();
        public w_so019()
        {
            InitializeComponent();
            dgv_so_ship_detail.AutoGenerateColumns = false;
            //dgv_so_pack_header.AutoGenerateColumns = false;
            //cmb_send_type.Visible = false;  //先不让它显示            
            //dgv_so_pack_header.Controls.Add(cmb_send_type);
            //cmb_send_type.DropDownStyle = ComboBoxStyle.DropDownList;
            //cmb_send_type.MouseLeave += new EventHandler(cmb_send_type_Change); //为时间控件加入事件dtp_TextChange
            //cmb_send_type.TextChanged += new EventHandler(cmb_send_type_TextChanged);
        }

        void cmb_send_type_TextChanged(object sender, EventArgs e)
        {
            ////if ((dgv_so_pack_header.Columns[e.ColumnIndex].Name.Trim() == "net_weight_so_pack_header") && (dgv_so_pack_header.CurrentRow.Cells["net_weight_so_pack_header"].Value.ToString().Trim() != ""))
            ////{
            //    if (Convert.ToDouble(dgv_so_pack_header.CurrentRow.Cells["net_weight_so_pack_header"].Value.ToString().Trim()) <= 20)
            //    {
            //        dgv_so_pack_header.CurrentRow.Cells["send_type_so_pack_header"].Value = "包裹";
            //        if (ds_address.Tables[0].Rows.Count > 0)
            //            dgv_so_pack_header.CurrentRow.Cells["standby"].Value = ds_address.Tables[0].Rows[0]["standby_11"].ToString().Trim();
            //    }
            //    else
            //    {
            //        dgv_so_pack_header.CurrentRow.Cells["send_type_so_pack_header"].Value = "公路";
            //        if (ds_address.Tables[0].Rows.Count > 0)
            //            dgv_so_pack_header.CurrentRow.Cells["standby"].Value = ds_address.Tables[0].Rows[0]["standby_12"].ToString().Trim();
            //    }
            //}
        }

        private void cbHeader_CheckedChanged(object sender, EventArgs e)
        {
            dgv_so_pack_header.EndEdit();
            foreach (DataGridViewRow dr in dgv_so_pack_header.Rows)
                dr.Cells[0].Value = ((CheckBox)dgv_so_pack_header.Controls.Find("checkboxHeader", true)[0]).Checked;
            
        }

        private void cbHeader2_CheckedChanged(object sender, EventArgs e)
        {
            dgv_so_ship_detail.EndEdit();
            
            foreach (DataGridViewRow dr in dgv_so_ship_detail.Rows)
            {
                //改变CheckBox状态
                //if ((bool)dr.Cells["check_uc"].EditedFormattedValue)
                //{
                //    dr.Cells["check_uc"].Value = "0";
                //    dr.Cells["confirm_qty_m"].Value = "0";
                //    ////将已扫的SKU取消
                //    //DataTable dt = new DataTable();
                //    //dgv_sku_add.DataSource = dt;
                //}
                //else
                //{
                //    dr.Cells["check_uc"].Value = "1";
                //    dr.Cells["confirm_qty_m"].Value = dr.Cells["unbox_qty"].Value;
                //}
                //dr.Cells["check_uc"].Value = ((TextBox)dgv_so_ship_detail.Controls.Find("check_uc",)[0]).Checked;
                //dr.Cells["confirm_qty_m"].Value = ((TextBox)dgv_so_ship_detail.Controls.Find("check_uc", true)[0]).Checked;

                dr.Cells[0].Value = ((CheckBox)dgv_so_ship_detail.Controls.Find("check_uc", true)[0]).Checked;
                
                
            }
            for (int i = 0; i < dgv_so_ship_detail.Rows.Count; i++)
            {
                if (dgv_so_ship_detail.Rows[i].Cells["check_uc"].Value.ToString() == "True")
                {
                    dgv_so_ship_detail.Rows[i].Cells["confirm_qty_m"].Value = dgv_so_ship_detail.Rows[i].Cells["unbox_qty"].Value;
                }
                else
                {
                    dgv_so_ship_detail.Rows[i].Cells["confirm_qty_m"].Value = "0";
                }
            }
            

        }

        private void w_so019_Load(object sender, EventArgs e)
        {
            #region 建立全选 CheckBox
            Rectangle rect = dgv_so_pack_header.GetCellDisplayRectangle(0, -1, true);
            rect.X = rect.Location.X + rect.Width / 4;
            rect.Y = rect.Location.Y + (rect.Height / 2 - 9);
            CheckBox cbHeader = new CheckBox();
            cbHeader.Name = "checkboxHeader";
            cbHeader.Size = new Size(18, 18);
            cbHeader.Location = rect.Location;
            //全选要设定的事件
            cbHeader.CheckedChanged += new EventHandler(cbHeader_CheckedChanged);
            //将 CheckBox 加入到 dataGridView
            dgv_so_pack_header.Controls.Add(cbHeader);
            #endregion

            #region 建立全选 CheckBox
            Rectangle rect2 = dgv_so_ship_detail.GetCellDisplayRectangle(0, -1, true);
            rect.X = rect2.Location.X + rect.Width / 4;
            rect.Y = rect2.Location.Y + (rect.Height / 2 - 9);
            CheckBox cbHeader2 = new CheckBox();
            cbHeader2.Name = "check_uc";
            cbHeader2.Size = new Size(18, 18);
            cbHeader2.Location = rect.Location;
            //全选要设定的事件
            cbHeader2.CheckedChanged += new EventHandler(cbHeader2_CheckedChanged);
            //将 CheckBox 加入到 dataGridView
            dgv_so_ship_detail.Controls.Add(cbHeader2);
            #endregion

            this.cmb_type.SelectedIndex = 1;
            //初始化货主编码 
            try
            {
                dscustomer = main.g_class.comm_get_consignor();
                cbx_head_consignor.ValueMember = "consignor";
                cbx_head_consignor.DisplayMember = "consignor";
                DataRow drnew3;
                drnew3 = dscustomer.Tables[0].NewRow();
                drnew3["consignor"] = "";
                drnew3["consignor_name"] = "";
                dscustomer.Tables[0].Rows.Add(drnew3);
                cbx_head_consignor.DataSource = dscustomer.Tables[0];
                if (dscustomer.Tables[0].Rows.Count > 0)
                {
                    tb_head_consignor.Text = dscustomer.Tables[0].Rows[0][1].ToString().Trim();
                }
                cbx_head_consignor.Text = "";
                //语言转换
                main.g_class.comm_changeControl(this, main.g_win_dataset);
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Consignor's Information", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }

            DataSet ds_temp_2 = new DataSet();
            ds_temp_2.Tables.Add("0");
            ds_temp_2.Tables[0].Columns.Add("send_type");
            ds_temp_2.Tables[0].Columns.Add("send_type_name");
            DataRow drnew;
            drnew = ds_temp_2.Tables[0].NewRow();
            drnew["send_type"] = "0";
            drnew["send_type_name"] = "包裹";
            ds_temp_2.Tables[0].Rows.Add(drnew);

            DataRow drnew2;
            drnew2 = ds_temp_2.Tables[0].NewRow();
            drnew2["send_type"] = "1";
            drnew2["send_type_name"] = "公路";
            ds_temp_2.Tables[0].Rows.Add(drnew2);

            DataRow drnew30;
            drnew30 = ds_temp_2.Tables[0].NewRow();
            drnew30["send_type"] = "";
            drnew30["send_type_name"] = "";
            ds_temp_2.Tables[0].Rows.Add(drnew30);

            DataGridViewComboBoxColumn dgvComboBoxColumn = dgv_so_pack_header.Columns["send_type_so_pack_header"] as DataGridViewComboBoxColumn;
            //dgvComboBoxColumn.DataPropertyName = "transaction_type";               
            dgvComboBoxColumn.DataSource = ds_temp_2.Tables[0].Copy();//必须在设置dataGridView1的DataSource的属性前设置
            dgvComboBoxColumn.DisplayMember = "send_type_name";
            dgvComboBoxColumn.ValueMember = "send_type";
            //if (dgvComboBoxColumn. == "公路")
            //    dgvComboBoxColumn.SelectedIndex = 1;
            //else
            //    dgvComboBoxColumn.SelectedIndex = 0;

            
        }

        private void cbx_head_consignor_TextChanged(object sender, EventArgs e)
        {
            string str_cust;
            str_cust = cbx_head_consignor.Text.Trim();
            tb_head_consignor.Text = main.g_class.comm_findname(str_cust, dscustomer);
        }

        private void btn_Query_Click(object sender, EventArgs e)
        {
            if (this.cmb_type.SelectedIndex == 0)
            {


                //查询语句
                string s_sql;
                s_sql = "select  so_no,consignor,customer_sale_no,customer_name,ship_day,so_type from " + main.g_space + ".so_ship_header where inv_org='" + main.g_org + "'";

                #region 拼接查询条件
                //货主编码
                if (!string.IsNullOrEmpty(cbx_head_consignor.Text))
                {
                    s_sql += " and consignor like '%" + cbx_head_consignor.Text + "%'";
                }

                //出库单
                if (!string.IsNullOrEmpty(tb_so.Text))
                {
                    s_sql += " and so_no like '%" + tb_so.Text + "%'";
                }

                //外部单号
                if (!string.IsNullOrEmpty(tb_customer_sale_no.Text))
                {
                    s_sql += " and customer_sale_no like '%" + tb_customer_sale_no.Text + "%'";
                }

                //出库类型
                if (!string.IsNullOrEmpty(tb_so_type.Text))
                {
                    s_sql += " and so_type like '%" + tb_so_type.Text + "%'";
                }

                //客户名称
                if (!string.IsNullOrEmpty(tb_customer_name.Text))
                {
                    s_sql += " and customer_name like '%" + tb_customer_name.Text + "%'";
                }

                //出货时间
                s_sql += " and confirm_day between '" + dtp_ship_day_begin.Value.ToString("yyyy.MM.dd") + "' and '" + Convert.ToDateTime(dtp_ship_day_end.Value.ToString("yyyy.MM.dd")).AddDays(1).ToString("yyyy.MM.dd") + "'";

                //维护区分和状态为5
                s_sql += " and main_dist<>'D' and so_status in ('3','4') and wave_flag ='0'";

                //排序
                s_sql += " order by consignor,so_no";

                #endregion

                try
                {
                    if (main.dbtype == "SQL")
                    {
                        ds_temp = main.dbservice.Sql_exec_selectsql(s_sql);
                    }
                    else
                    {
                        ds_temp = main.dbservice.oracle_exec_selectsql(s_sql);
                    }

                    dgv_so_ship_header.DataSource = ds_temp.Tables[0];
                    //if (this.dgv_so_ship_header.Columns["wave_no"].Visible == true)
                    //    this.dgv_so_ship_header.Columns["wave_no"].Visible = false;
                    if (this.dgv_so_ship_header.Columns["so_no"].Visible == false)
                        this.dgv_so_ship_header.Columns["so_no"].Visible = true;
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ee.ToString());
                    return;
                }
                dgv_so_ship_detail.DataSource = null;
                //dgv_so_pack_header.DataSource = null;
                if (dgv_so_pack_header.Rows.Count > 0)
                {
                    DataTable dt = new DataTable();
                    //清空dgv_so_pack_header
                    dt = dgv_so_pack_header.DataSource as DataTable;
                    dt.Rows.Clear();
                    dgv_so_pack_header.DataSource = dt;
                }
                if (dgv_so_pack_detail.Rows.Count > 0)
                {
                    DataTable dt = new DataTable();
                    //清空dgv_so_pack_header
                    dt = dgv_so_pack_detail.DataSource as DataTable;
                    dt.Rows.Clear();
                    dgv_so_pack_detail.DataSource = dt;
                }
            }
            else
            {

                //查询语句
                string s_sql;
                s_sql = "select a.wave_no,a.consignor,b.so_no,c.customer_code,c.address from " + main.g_space + ".so_ship_wave a, " + main.g_space + ".so_ship_wavedetail b," + main.g_space + ".so_ship_header c  where a.inv_org = b.inv_org and a.consignor = b.consignor and a.wave_no = b.wave_no and b.inv_org =c.inv_org and b.consignor =c.consignor and b.so_no = c.so_no and a.inv_org='" + main.g_org + "' and a.wave_status ='2' ";

                #region 拼接查询条件
                //货主编码
                if (!string.IsNullOrEmpty(cbx_head_consignor.Text))
                {
                    s_sql += " and a.consignor like '%" + cbx_head_consignor.Text + "%'";
                }

                //出库单
                if (!string.IsNullOrEmpty(tb_so.Text))
                {
                    s_sql += " and a.wave_no like '%" + tb_so.Text + "%'";
                }

                //外部单号
                //if (!string.IsNullOrEmpty(tb_customer_sale_no.Text))
                //{
                //    s_sql += " and customer_sale_no like '%" + tb_customer_sale_no.Text + "%'";
                //}

                //出库类型
                //if (!string.IsNullOrEmpty(tb_so_type.Text))
                //{
                //    s_sql += " and so_type like '%" + tb_so_type.Text + "%'";
                //}

                //客户名称
                //if (!string.IsNullOrEmpty(tb_customer_name.Text))
                //{
                //    s_sql += " and customer_name like '%" + tb_customer_name.Text + "%'";
                //}

                //出货时间
                s_sql += " and a.confirm_day between '" + dtp_ship_day_begin.Value.ToString("yyyy.MM.dd") + "' and '" + Convert.ToDateTime(dtp_ship_day_end.Value.ToString("yyyy.MM.dd")).AddDays(1).ToString("yyyy.MM.dd") + "'";

                //维护区分和状态为5
                s_sql += " and a.main_dist<>'D'  and  not exists (select 1 from wms.so_delivery_detail c where b.inv_org = c.inv_org and b.consignor = c.consignor and b.so_no = c.so_no) ";

                //排序
                s_sql += " order by a.wave_no";

                #endregion

                try
                {
                    if (main.dbtype == "SQL")
                    {
                        ds_temp_wave = main.dbservice.Sql_exec_selectsql(s_sql);
                    }
                    else
                    {
                        ds_temp_wave = main.dbservice.oracle_exec_selectsql(s_sql);
                    }

                    dgv_so_ship_header.DataSource = ds_temp_wave.Tables[0];
                    if (this.dgv_so_ship_header.Columns["wave_no"].Visible == false)
                        this.dgv_so_ship_header.Columns["wave_no"].Visible = true;
                    //if (this.dgv_so_ship_header.Columns["so_no"].Visible==true)
                    //    this.dgv_so_ship_header.Columns["so_no"].Visible = false;

                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ee.ToString());
                    return;
                }
                dgv_so_ship_detail.DataSource = null;
                if (dgv_so_pack_header.Rows.Count > 0)
                {
                    DataTable dt = new DataTable();
                    //清空dgv_so_pack_header
                    dt = dgv_so_pack_header.DataSource as DataTable;
                    dt.Rows.Clear();
                    dgv_so_pack_header.DataSource = dt;
                }

                if (dgv_so_pack_detail.Rows.Count > 0)
                {
                    DataTable dt = new DataTable();
                    //清空dgv_so_pack_header
                    dt = dgv_so_pack_detail.DataSource as DataTable;
                    dt.Rows.Clear();
                    dgv_so_pack_detail.DataSource = dt;
                }
            }
        }

        private void dgv_so_ship_header_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            if (dgv_so_ship_header.Columns[dgv_so_ship_header.CurrentCell.ColumnIndex].Name.ToString().Trim() == "check")
            {
                if (dgv_so_ship_header.IsCurrentCellDirty)
                {
                    dgv_so_ship_header.CommitEdit(DataGridViewDataErrorContexts.Commit);
                }
            }
        }

        private void dgv_so_ship_header_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            ds = new DataSet();
            ds_wave = new DataSet();
            ds_s = new DataSet();
            ds_wave_s = new DataSet();
            i_ds_so_pack_header = new DataSet();
            i_ds_so_pack_detail = new DataSet();
            String i_consignor = "";
            string i_wave_no = "";
            String s_consignor = "";
            String i_so_no = "";
            //String s_so_no = "";
            String s_sql = "";
            string s_sql_wave = "";
            String s_sql_s = "";
            string s_sql_s_wave = "";
            String i_sql_so_pack_header = "";
            String i_sql_so_pack_detail = "";
            String i_sql_so_pack_header_s = "";
            #region 打钩
            if (this.cmb_type.SelectedIndex == 1)
            {
                if (e.ColumnIndex == 0 && e.RowIndex != -1)
                {
                    if (this.dgv_so_ship_header.Columns[e.ColumnIndex].Name == "check")
                    {
                        if (this.dgv_so_ship_header.Rows[e.RowIndex].Cells["check"].Value.ToString().Trim() == "1")
                        {
                            string s_wave_no = this.dgv_so_ship_header.Rows[e.RowIndex].Cells["wave_no"].Value.ToString().Trim();
                            for (int i = 0; i < dgv_so_ship_header.Rows.Count; i++)
                            {
                                if (this.dgv_so_ship_header.Rows[i].Cells["wave_no"].Value.ToString().Trim() == s_wave_no)
                                {
                                    this.dgv_so_ship_header.Rows[i].Cells["check"].Value = 1;
                                }
                            }
                        }
                        else
                        {
                            string s_wave_no = this.dgv_so_ship_header.Rows[e.RowIndex].Cells["wave_no"].Value.ToString().Trim();
                            for (int i = 0; i < dgv_so_ship_header.Rows.Count; i++)
                            {
                                if (this.dgv_so_ship_header.Rows[i].Cells["wave_no"].Value.ToString().Trim() == s_wave_no)
                                {
                                    this.dgv_so_ship_header.Rows[i].Cells["check"].Value = 0;
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            if (e.ColumnIndex == 0 && e.RowIndex != -1)
            {
                if (this.dgv_so_ship_header.Columns[e.ColumnIndex].Name == "check")
                {
                    for (int i = 0; i < dgv_so_ship_header.Rows.Count; i++)
                    {
                        if (this.dgv_so_ship_header.Rows[i].Cells[0].EditedFormattedValue.ToString() == "True")
                        {
                            i_consignor = dgv_so_ship_header.Rows[i].Cells["consignor"].Value.ToString().Trim();

                            if (this.cmb_type.SelectedIndex == 1)
                                i_wave_no = dgv_so_ship_header.Rows[i].Cells["wave_no"].Value.ToString().Trim();
                            i_so_no = dgv_so_ship_header.Rows[i].Cells["so_no"].Value.ToString().Trim();
                            //s_so_no = "1";
                            s_consignor = s_consignor + "'" + dgv_so_ship_header.Rows[i].Cells["consignor"].Value.ToString().Trim() + "',";
                            try   
                            { 
                                if (main.dbtype == "SQL")
                                {
                                    if (this.cmb_type.SelectedIndex == 0)
                                    {
                                        s_sql = s_sql + " select 'False' check_uc,a.consignor,ltrim(rtrim(a.so_no)) so_no,a.so_line_no,ltrim(rtrim(a.sku)) sku,b.sku_name,isnull(a.pick_qty_m,0) pick_qty_m,isnull(a.pick_qty_m,0)-isnull(c.box_qty,0) unbox_qty,'0' confirm_qty_m,isnull(c.box_qty,0) box_qty,a.pack_code pack_code,isnull(a.pick_qty_s,0) pick_qty_s,a.order_price order_price,a.order_unit order_unit,isnull(a.pick_cubage,0) pick_cubage,isnull(a.pick_gross_weight,0) pick_gross_weight,isnull(a.pick_net_weight,0) pick_net_weight,a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus,b.gross_weight " +
                                               "from " + main.g_space + ".so_ship_detail a left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku left join" +
                                               "(select so_line_no,sum(isnull(ship_qty_m,0)) box_qty from " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' group by so_line_no) c on a.so_line_no=c.so_line_no " +
                                               "where  a.so_status ='4' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                        s_sql_s = s_sql_s + " select 'False' check_uc,a.consignor,ltrim(rtrim(a.so_no)) so_no,a.so_line_no,ltrim(rtrim(a.sku)) sku,b.sku_name,isnull(a.pick_qty_m,0) pick_qty_m,isnull(a.pick_qty_m,0)-isnull(c.box_qty,0) unbox_qty,'0' confirm_qty_m,isnull(c.box_qty,0) box_qty,a.pack_code pack_code,isnull(a.pick_qty_s,0) pick_qty_s,a.order_price order_price,a.order_unit order_unit,isnull(a.pick_cubage,0) pick_cubage,isnull(a.pick_gross_weight,0) pick_gross_weight,isnull(a.pick_net_weight,0) pick_net_weight,a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus,b.gross_weight " +
                                               "from " + main.g_space + ".so_ship_detail a left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku left join" +
                                               "(select so_line_no,sum(isnull(ship_qty_m,0)) box_qty from " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' group by so_line_no) c on a.so_line_no=c.so_line_no " +
                                               "where  a.so_status ='4' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                        i_sql_so_pack_header += "  select rtrim(ltrim(a.send_no)) send_no,rtrim(ltrim(a.consignor)) consignor,rtrim(ltrim(a.box_no)) box_no,rtrim(ltrim(a.net_weight)) net_weight,case ltrim(rtrim(a.send_type)) when '' then NULL else a.send_type end send_type,case a.send_type when '0' then b.standby_11 when '1' then b.standby_12 else '' end standby,a.address,rtrim(ltrim(a.spec)) spec,rtrim(ltrim(a.box_size)) box_size,rtrim(ltrim(a.inv_org)) inv_org ,a.memo,a.standby_1 from " + main.g_space + ".so_pack_header a , " + main.g_space + ".so_ship_header b " +
                                                " where a.inv_org = b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no and a.status ='0' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                        i_sql_so_pack_header_s += " select  rtrim(ltrim(a.send_no)) send_no,rtrim(ltrim(a.consignor)) consignor,rtrim(ltrim(a.box_no)) box_no,rtrim(ltrim(a.net_weight)) net_weight,case ltrim(rtrim(a.send_type)) when '' then NULL else a.send_type end send_type,case a.send_type when '0' then b.standby_11 when '1' then b.standby_12 else '' end standby,a.address,rtrim(ltrim(a.spec)) spec,rtrim(ltrim(a.box_size)) box_size,rtrim(ltrim(a.inv_org)) inv_org,  a.memo from " + main.g_space + ".so_pack_header a , " + main.g_space + ".so_ship_header b " +
                                                " where a.inv_org = b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no and a.status ='0' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                        //i_sql_so_pack_header += " select distinct(rtrim(ltrim(box_no))) box_no,rtrim(ltrim(inv_org)) inv_org,rtrim(ltrim(consignor)) consignor,rtrim(ltrim(spec)) spec,rtrim(ltrim(box_size)) box_size,rtrim(ltrim(net_weight)) net_weight,rtrim(ltrim(send_no)) send_no from " + main.g_space + ".so_pack_header " +
                                        //        "where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "'  union";
                                        //i_sql_so_pack_header_s += " select distinct(rtrim(ltrim(box_no))) box_no,rtrim(ltrim(inv_org)) inv_org,rtrim(ltrim(consignor)) consignor,rtrim(ltrim(spec)) spec,rtrim(ltrim(box_size)) box_size,rtrim(ltrim(net_weight)) net_weight,rtrim(ltrim(send_no)) send_no from " + main.g_space + ".so_pack_header " +
                                        //        "where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' union";
                                        i_sql_so_pack_detail += " select a.consignor,a.so_no,a.box_no,a.so_line_no,a.sku,b.sku_name,a.ship_qty_m ,a.memo,b.gross_weight from " + main.g_space + ".so_pack_detail a " +
                                                       "left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku " +
                                                       "where a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                    }
                                    //波次拣货
                                    else  
                                    {
                                        s_sql_wave = s_sql_wave + " select 'False' check_uc,a.consignor,ltrim(rtrim(a.so_no)) so_no,a.so_line_no,ltrim(rtrim(a.sku)) sku,b.sku_name,isnull(a.pick_qty_m,0) pick_qty_m,isnull(a.pick_qty_m,0)-isnull(c.box_qty,0) unbox_qty,'0' confirm_qty_m,isnull(c.box_qty,0) box_qty,a.pack_code pack_code,isnull(a.pick_qty_s,0) pick_qty_s,a.order_price order_price,a.order_unit order_unit,isnull(a.pick_cubage,0) pick_cubage,isnull(a.pick_gross_weight,0) pick_gross_weight,isnull(a.pick_net_weight,0) pick_net_weight,a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus,b.gross_weight " +
                                               "from " + main.g_space + ".so_ship_detail a left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku left join" +
                                               "(select so_line_no,sum(isnull(ship_qty_m,0)) box_qty from " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' group by so_line_no) c on a.so_line_no=c.so_line_no " +
                                               "where  a.so_status ='4' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                        s_sql_s_wave = s_sql_s_wave + " select 'False' check_uc,a.consignor,ltrim(rtrim(a.so_no)) so_no,a.so_line_no,ltrim(rtrim(a.sku)) sku,b.sku_name,isnull(a.pick_qty_m,0) pick_qty_m,isnull(a.pick_qty_m,0)-isnull(c.box_qty,0) unbox_qty,'0' confirm_qty_m,isnull(c.box_qty,0) box_qty,a.pack_code pack_code,isnull(a.pick_qty_s,0) pick_qty_s,a.order_price order_price,a.order_unit order_unit,isnull(a.pick_cubage,0) pick_cubage,isnull(a.pick_gross_weight,0) pick_gross_weight,isnull(a.pick_net_weight,0) pick_net_weight,a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus ,b.gross_weight " +
                                               "from " + main.g_space + ".so_ship_detail a left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku left join" +
                                               "(select so_line_no,sum(isnull(ship_qty_m,0)) box_qty from " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' group by so_line_no) c on a.so_line_no=c.so_line_no " +
                                               "where  a.so_status ='4' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                        //s_sql_wave += " select a.wave_no, '0' check_uc,a.consignor,ltrim(rtrim(a.sku)) sku,b.sku_name,isnull(a.pick_qty_m,0) pick_qty_m,isnull(a.pick_qty_m,0)-isnull(c.ship_qty_m,0) unbox_qty,'0' confirm_qty_m,isnull(c.ship_qty_m,0) box_qty,a.pack_code pack_code,isnull(a.pick_qty_s,0) pick_qty_s,a.order_price order_price,a.order_unit order_unit,isnull(a.pick_cubage,0) pick_cubage,isnull(a.pick_gross_weight,0) pick_gross_weight,isnull(a.pick_net_weight,0) pick_net_weight, "+
                                        //                "a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus from " + main.g_space + ".mst_sku b, (select sum(ship_qty_m) ship_qty_m,inv_org,consignor,so_no,box_no,sku,so_line_no from " + main.g_space + ".so_pack_detail where so_no = '" + i_wave_no + "' and consignor='"+i_consignor+"' group by inv_org,consignor,so_no,box_no,sku,so_line_no) c, (select wave_no,pack_code,order_price,order_unit,pick_cubage,pick_gross_weight,pick_net_weight, main_sub_flag,convert_modulus,  " +
                                        //                "sum(isnull(pick_qty_m,0)) pick_qty_m,sum(isnull(pick_qty_s,0)) pick_qty_s,inv_org,consignor,sku from " + main.g_space + ".so_pick_detail where wave_no = '" + i_wave_no + "'and consignor='"+i_consignor+"' group by inv_org,consignor,sku, wave_no,consignor,sku,pack_code,order_price,order_unit,pick_cubage,pick_gross_weight,pick_net_weight, main_sub_flag,convert_modulus) a  " +
                                        //                "where a.inv_org = b.inv_org and a.consignor = b.consignor and a.sku = b.sku and a.inv_org *= c.inv_org and a.consignor *=c.consignor and a.wave_no *= c.so_no and a.sku *= c.sku and a.wave_no ='" + i_wave_no + "' and a.consignor='"+i_consignor+"' union";
                                        //s_sql_s_wave += " select a.wave_no, '0' check_uc,a.consignor,ltrim(rtrim(a.sku)) sku,b.sku_name,isnull(a.pick_qty_m,0) pick_qty_m,isnull(a.pick_qty_m,0)-isnull(c.ship_qty_m,0) unbox_qty,'0' confirm_qty_m,isnull(c.ship_qty_m,0) box_qty,a.pack_code pack_code,isnull(a.pick_qty_s,0) pick_qty_s,a.order_price order_price,a.order_unit order_unit,isnull(a.pick_cubage,0) pick_cubage,isnull(a.pick_gross_weight,0) pick_gross_weight,isnull(a.pick_net_weight,0) pick_net_weight, " +
                                        //                "a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus from " + main.g_space + ".mst_sku b, (select sum(ship_qty_m) ship_qty_m,inv_org,consignor,so_no,box_no,sku,so_line_no from " + main.g_space + ".so_pack_detail where so_no = '" + i_wave_no + "' and consignor='" + i_consignor + "' group by inv_org,consignor,so_no,box_no,sku,so_line_no) c, (select wave_no,pack_code,order_price,order_unit,pick_cubage,pick_gross_weight,pick_net_weight, main_sub_flag,convert_modulus,  " +
                                        //                "sum(isnull(pick_qty_m,0)) pick_qty_m,sum(isnull(pick_qty_s,0)) pick_qty_s,inv_org,consignor,sku from " + main.g_space + ".so_pick_detail where wave_no = '" + i_wave_no + "'and consignor='" + i_consignor + "' group by inv_org,consignor,sku, wave_no,consignor,sku,pack_code,order_price,order_unit,pick_cubage,pick_gross_weight,pick_net_weight, main_sub_flag,convert_modulus) a  " +
                                        //                "where a.inv_org = b.inv_org and a.consignor = b.consignor and a.sku = b.sku and a.inv_org *= c.inv_org and a.consignor *=c.consignor and a.wave_no *= c.so_no and a.sku *= c.sku and a.wave_no ='" + i_wave_no + "' and a.consignor='" + i_consignor + "' union";
                                        //i_sql_so_pack_header += " select rtrim(ltrim(inv_org)) inv_org,rtrim(ltrim(consignor)) consignor,rtrim(ltrim(box_no)) box_no,rtrim(ltrim(spec)) spec,rtrim(ltrim(box_size)) box_size,rtrim(ltrim(net_weight)) net_weight,case send_type when '0' then '包裹' when '1' then '公路' else '' end send_type,address,rtrim(ltrim(send_no)) send_no " +
                                        //                       "from " + main.g_space + ".so_pack_header where status ='0' and inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '"+i_wave_no+"'"+
                                        //                       " group by rtrim(ltrim(inv_org)) ,rtrim(ltrim(consignor)) ,rtrim(ltrim(box_no)) ,rtrim(ltrim(spec)),rtrim(ltrim(box_size)),rtrim(ltrim(net_weight)),send_type ,address,rtrim(ltrim(send_no)) union";
                                        //i_sql_so_pack_header_s += " select rtrim(ltrim(inv_org)) inv_org,rtrim(ltrim(consignor)) consignor,rtrim(ltrim(box_no)) box_no,rtrim(ltrim(spec)) spec,rtrim(ltrim(box_size)) box_size,rtrim(ltrim(net_weight)) net_weight,case send_type when '0' then '包裹' when '1' then '公路' else '' end send_type,address,rtrim(ltrim(send_no)) send_no " +
                                        //                       "from " + main.g_space + ".so_pack_header where status ='0' and inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no ='"+i_wave_no+"'"+
                                        //                       " group by rtrim(ltrim(inv_org)) ,rtrim(ltrim(consignor)) ,rtrim(ltrim(box_no)) ,rtrim(ltrim(spec)),rtrim(ltrim(box_size)),rtrim(ltrim(net_weight)),send_type ,address,rtrim(ltrim(send_no)) union";
                                        //i_sql_so_pack_detail += " select a.consignor,a.so_no,a.box_no,a.so_line_no,a.sku,b.sku_name,a.ship_qty_m from " + main.g_space + ".so_pack_detail a left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku where a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' " +
                                        //                        "and a.so_no ='"+i_wave_no+"'  union";
                                        i_sql_so_pack_header += "  select distinct rtrim(ltrim(a.box_no)) box_no, rtrim(ltrim(a.send_no)) send_no,rtrim(ltrim(a.consignor)) consignor,rtrim(ltrim(a.net_weight)) net_weight,case ltrim(rtrim(a.send_type)) when '' then NULL else a.send_type end send_type,case a.send_type when '0' then b.standby_11 when '1' then b.standby_12 else '' end standby,a.address,rtrim(ltrim(a.spec)) spec,rtrim(ltrim(a.box_size)) box_size,rtrim(ltrim(a.inv_org)) inv_org,a.memo,a.standby_1  from " + main.g_space + ".so_pack_header a , " + main.g_space + ".so_ship_header b " +
                                                " where a.inv_org = b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no and a.status ='0' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                        i_sql_so_pack_header_s += " select distinct rtrim(ltrim(a.box_no)) box_no, rtrim(ltrim(a.send_no)) send_no,rtrim(ltrim(a.consignor)) consignor,rtrim(ltrim(a.net_weight)) net_weight,case ltrim(rtrim(a.send_type)) when '' then NULL else a.send_type end send_type,case a.send_type when '0' then b.standby_11 when '1' then b.standby_12 else '' end standby,a.address,rtrim(ltrim(a.spec)) spec,rtrim(ltrim(a.box_size)) box_size,rtrim(ltrim(a.inv_org)) inv_org ,a.memo from " + main.g_space + ".so_pack_header a , " + main.g_space + ".so_ship_header b " +
                                                " where a.inv_org = b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no and a.status ='0' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                        i_sql_so_pack_detail += " select a.consignor,a.so_no,a.box_no,a.so_line_no,a.sku,b.sku_name,a.ship_qty_m ,a.memo,b.gross_weight from " + main.g_space + ".so_pack_detail a " +
                                                       "left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku " +
                                                       "where a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                    }
                                }
                                else
                                {
                                    s_sql = s_sql + " select 'False' check_uc,a.consignor,a.so_no,a.so_line_no,a.sku,b.sku_name,nvl(a.pick_qty_m,0) pick_qty_m,nvl(a.pick_qty_m,0)-nvl(c.box_qty,0) unbox_qty,'0' confirm_qty_m,nvl(c.box_qty,0) box_qty,a.pack_code pack_code,a.pick_qty_s pick_qty_s,a.order_price order_price,a.order_unit order_unit,nvl(a.pick_cubage,0) pick_cubage,nvl(a.pick_gross_weight,0) pick_gross_weight,nvl(a.pick_net_weight,0) pick_net_weight,a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus,b.gross_weight " +
                                          "from " + main.g_space + ".so_ship_detail a left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku left join" +
                                          "(select so_line_no,sum(nvl(ship_qty_m,0)) box_qty from " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' group by so_line_no) c on a.so_line_no=c.so_line_no " +
                                          "where a.so_status ='4' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no ='" + i_so_no + "' union";
                                    s_sql_s = s_sql_s + " select 'False' check_uc,a.consignor,a.so_no,a.so_line_no,a.sku,b.sku_name,nvl(a.pick_qty_m,0) pick_qty_m,nvl(a.pick_qty_m,0)-nvl(c.box_qty,0) unbox_qty,'0' confirm_qty_m,nvl(c.box_qty,0) box_qty,a.pack_code pack_code,a.pick_qty_s pick_qty_s,a.order_price order_price,a.order_unit order_unit,nvl(a.pick_cubage,0) pick_cubage,nvl(a.pick_gross_weight,0) pick_gross_weight,nvl(a.pick_net_weight,0) pick_net_weight,a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus ,b.gross_weight " +
                                          "from " + main.g_space + ".so_ship_detail a left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku left join" +
                                          "(select so_line_no,sum(nvl(ship_qty_m,0)) box_qty from " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' group by so_line_no) c on a.so_line_no=c.so_line_no " +
                                          "where a.so_status ='4' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no ='" + i_so_no + "' union";
                                    i_sql_so_pack_header += " select inv_org,consignor,trim(box_no) box_no,spec,box_size,net_weight,case send_type when '0' then '包裹' when '1' then '公路' else '' end send_type,address,send_no from " + main.g_space + ".so_pack_header " +
                                        "where status ='0' and inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' union";
                                    i_sql_so_pack_header_s += " select inv_org,consignor,trim(box_no) box_no,spec,box_size,net_weight,case send_type when '0' then '包裹' when '1' then  '公路' else '' end send_type,address,send_no from " + main.g_space + ".so_pack_header " +
                                        "where status ='0' and inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' union";
                                    //i_sql_so_pack_header += " select distinct(trim(box_no)) box_no,inv_org,consignor,spec,box_size,net_weight,send_no from " + main.g_space + ".so_pack_header " +
                                    //    "where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + " ' union";
                                    //i_sql_so_pack_header_s += " select distinct(trim(box_no)) box_no,inv_org,consignor,spec,box_size,net_weight,send_no from " + main.g_space + ".so_pack_header " +
                                    //    "where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + " ' union";
                                    i_sql_so_pack_detail += " select a.consignor,a.so_no,a.box_no,a.so_line_no,a.sku,b.sku_name,a.ship_qty_m,a.memo,b.gross_weight from " + main.g_space + ".so_pack_detail a " +
                                                   "left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku " +
                                                   "where a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                }
                                   

                            }
                            catch (System.Exception ee)
                            {
                                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ee.ToString());
                                return;
                            }

                        }
                    }


                    //绑定ship_datail
                    if ((s_sql.Length > 0) || (s_sql_wave.Length > 0))
                    {
                        if (this.cmb_type.Text == "一单拣货")
                        {
                            s_sql = s_sql.Substring(0, s_sql.Length - 5) + " order by a.so_line_no ";
                            s_sql_s = s_sql_s.Substring(0, s_sql_s.Length - 5) + " order by a.so_line_no ";
                        }
                        else
                        {
                            s_sql_wave = s_sql_wave.Substring(0, s_sql_wave.Length - 5) + " order by a.so_no,a.so_line_no,a.sku ";
                            s_sql_s_wave = s_sql_s_wave.Substring(0, s_sql_s_wave.Length - 5) + " order by a.so_no,a.so_line_no,a.sku ";
                        }
                        try
                        {
                            if (main.dbtype == "SQL")
                            {
                                if (this.cmb_type.Text == "一单拣货")
                                {
                                    ds = main.dbservice.Sql_exec_selectsql(s_sql);
                                    ds_s = main.dbservice.Sql_exec_selectsql(s_sql_s);
                                }
                                else
                                {
                                    ds_wave = main.dbservice.Sql_exec_selectsql(s_sql_wave);
                                    ds_wave_s = main.dbservice.Sql_exec_selectsql(s_sql_s_wave);
                                }
                            }
                            else
                            {
                                ds = main.dbservice.oracle_exec_selectsql(s_sql);
                                ds_s = main.dbservice.oracle_exec_selectsql(s_sql_s);
                            }
                            if (this.cmb_type.SelectedIndex == 0)
                                dgv_so_ship_detail.DataSource = ds.Tables[0];
                            else
                                dgv_so_ship_detail.DataSource = ds_wave.Tables[0];
                            if (dgv_so_ship_detail.Rows.Count > 0)
                            {
                                for (int i = 0; i < dgv_so_ship_detail.Rows.Count; i++)
                                {
                                    if (Convert.ToDouble(dgv_so_ship_detail.Rows[i].Cells["unbox_qty"].Value.ToString().Trim()) == 0.0000)
                                    {
                                        dgv_so_ship_detail.Rows[i].DefaultCellStyle.BackColor = Color.LightGreen;
                                    }
                                }
                            }
                        }
                        catch (System.Exception ex)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ex.ToString());
                            return;
                        }
                    }
                    else
                    {
                        if (dgv_so_ship_detail.Rows.Count > 0)
                        {
                            DataTable dt = new DataTable();
                            //清空so_pack_detail
                            dt = dgv_so_ship_detail.DataSource as DataTable;
                            dt.Rows.Clear();
                            dgv_so_ship_detail.DataSource = dt;
                        }
                    }

                    //绑定so_pack_header
                    if (i_sql_so_pack_header.Length > 0)
                    {
                        i_sql_so_pack_header = i_sql_so_pack_header.Substring(0, i_sql_so_pack_header.Length - 5);
                        i_sql_so_pack_header_s = i_sql_so_pack_header_s.Substring(0, i_sql_so_pack_header_s.Length - 5);
                        try
                        {
                            if (main.dbtype == "SQL")
                            {
                                i_ds_so_pack_header = main.dbservice.Sql_exec_selectsql(i_sql_so_pack_header);
                                i_ds_so_pack_header_s = main.dbservice.Sql_exec_selectsql(i_sql_so_pack_header_s);
                            }
                            else
                            {
                                i_ds_so_pack_header = main.dbservice.oracle_exec_selectsql(i_sql_so_pack_header);
                                i_ds_so_pack_header_s = main.dbservice.oracle_exec_selectsql(i_sql_so_pack_header);
                            }
                            dgv_so_pack_header.DataSource = i_ds_so_pack_header.Tables[0];
                            if (i_ds_so_pack_header.Tables[0].Rows.Count > 0)
                            {
                                btn_print.Enabled = true;
                            }
                            else
                            {
                                btn_print.Enabled = false;
                            }
                        }
                        catch (System.Exception ex)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ex.ToString());
                            return;
                        }

                    }
                    else
                    {
                        if (dgv_so_pack_header.Rows.Count > 0)
                        {
                            DataTable dt = new DataTable();
                            //清空so_pack_detail
                            dt = dgv_so_pack_header.DataSource as DataTable;
                            dt.Rows.Clear();
                            dgv_so_pack_header.DataSource = dt;
                            btn_print.Enabled = false;
                        }
                    }

                    //绑定so_pack_detail
                    if (i_sql_so_pack_detail.Length > 0)
                    {
                        i_sql_so_pack_detail = i_sql_so_pack_detail.Substring(0, i_sql_so_pack_detail.Length - 5);
                        try
                        {
                            if (main.dbtype == "SQL")
                            {
                                i_ds_so_pack_detail = main.dbservice.Sql_exec_selectsql(i_sql_so_pack_detail);
                            }
                            else
                            {
                                i_ds_so_pack_detail = main.dbservice.oracle_exec_selectsql(i_sql_so_pack_detail);
                            }
                            dgv_so_pack_detail.DataSource = i_ds_so_pack_detail.Tables[0];
                            if (i_ds_so_pack_detail.Tables[0].Rows.Count > 0)
                                btn_detail_print.Enabled = true;
                            else
                                btn_detail_print.Enabled = false;
                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ee.ToString());
                            return;
                        }
                    }
                    else
                    {
                        if (dgv_so_pack_detail.Rows.Count > 0)
                        {
                            DataTable dt = new DataTable();
                            //清空so_pack_detail
                            dt = dgv_so_pack_detail.DataSource as DataTable;
                            dt.Rows.Clear();
                            dgv_so_pack_detail.DataSource = dt;
                            btn_detail_print.Enabled = false;
                        }
                    }
                }
            }
        }

        //插入虚拟箱子后刷新虚拟箱子的数据
        private void f_refresh_virtule_box(string i_consignor, string i_so_no)
        {
            String i_sql_so_pack_header = "";
            String i_sql_so_pack_detail = "";
            i_ds_so_pack_header = new DataSet();
            i_ds_so_pack_detail = new DataSet();
            try
            {
                if (main.dbtype == "SQL")
                {
                    if (this.cmb_type.SelectedIndex == 0)
                    {
                        i_sql_so_pack_header += "  select rtrim(ltrim(a.send_no)) send_no,rtrim(ltrim(a.consignor)) consignor,rtrim(ltrim(a.box_no)) box_no,rtrim(ltrim(a.net_weight)) net_weight,case ltrim(rtrim(a.send_type)) when '' then NULL else a.send_type end send_type,case a.send_type when '0' then b.standby_11 when '1' then b.standby_12 else '' end standby,a.address,rtrim(ltrim(a.spec)) spec,rtrim(ltrim(a.box_size)) box_size,rtrim(ltrim(a.inv_org)) inv_org ,a.memo,a.standby_1 from " + main.g_space + ".so_pack_header a , " + main.g_space + ".so_ship_header b " +
                                " where a.inv_org = b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no and a.status ='0' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "'";
                        i_sql_so_pack_detail += " select a.consignor,a.so_no,a.box_no,a.so_line_no,a.sku,b.sku_name,a.ship_qty_m ,a.memo from " + main.g_space + ".so_pack_detail a " +
                                       "left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku " +
                                       "where a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "'";
                    }
                    //波次拣货
                    else
                    {
                        i_sql_so_pack_header += "  select distinct rtrim(ltrim(a.box_no)) box_no, rtrim(ltrim(a.send_no)) send_no,rtrim(ltrim(a.consignor)) consignor,rtrim(ltrim(a.net_weight)) net_weight,case ltrim(rtrim(a.send_type)) when '' then NULL else a.send_type end send_type,case a.send_type when '0' then b.standby_11 when '1' then b.standby_12 else '' end standby,a.address,rtrim(ltrim(a.spec)) spec,rtrim(ltrim(a.box_size)) box_size,rtrim(ltrim(a.inv_org)) inv_org,a.memo,a.standby_1  from " + main.g_space + ".so_pack_header a , " + main.g_space + ".so_ship_header b " +
                                " where a.inv_org = b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no and a.status ='0' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "'";
                        i_sql_so_pack_detail += " select a.consignor,a.so_no,a.box_no,a.so_line_no,a.sku,b.sku_name,a.ship_qty_m ,a.memo from " + main.g_space + ".so_pack_detail a " +
                                       "left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku " +
                                       "where a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "'";
                    }
                    i_ds_so_pack_header = main.dbservice.Sql_exec_selectsql(i_sql_so_pack_header);
                    i_ds_so_pack_detail = main.dbservice.Sql_exec_selectsql(i_sql_so_pack_detail);
                }
                else
                {
                    i_sql_so_pack_header += " select inv_org,consignor,trim(box_no) box_no,spec,box_size,net_weight,case send_type when '0' then '包裹' when '1' then '公路' else '' end send_type,address,send_no from " + main.g_space + ".so_pack_header " +
                        "where status ='0' and inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "'";
                    i_sql_so_pack_detail += " select a.consignor,a.so_no,a.box_no,a.so_line_no,a.sku,b.sku_name,a.ship_qty_m,a.memo from " + main.g_space + ".so_pack_detail a " +
                                   "left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku " +
                                   "where a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "'";
                    i_ds_so_pack_header = main.dbservice.oracle_exec_selectsql(i_sql_so_pack_header);
                    i_ds_so_pack_detail = main.dbservice.oracle_exec_selectsql(i_sql_so_pack_detail);
                }
                dgv_so_pack_header.DataSource = i_ds_so_pack_header.Tables[0];
                dgv_so_pack_detail.DataSource = i_ds_so_pack_detail.Tables[0];
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }
        }

        private void so_bind()
        {
            ds = new DataSet();
            ds_wave = new DataSet();
            ds_s = new DataSet();
            i_ds_so_pack_header = new DataSet();
            i_ds_so_pack_detail = new DataSet();
            String i_consignor = "";
            string i_wave_no = "";
            String s_consignor = "";
            String i_so_no = "";
            //String s_so_no = "";
            String s_sql = "";
            String s_sql_s = "";
            string s_sql_wave = "";
            string s_sql_s_wave = "";
            String i_sql_so_pack_header = "";
            String i_sql_so_pack_detail = "";
            String i_sql_so_pack_header_s = "";
            for (int i = 0; i < dgv_so_ship_header.Rows.Count; i++)
            {
                if (this.dgv_so_ship_header.Rows[i].Cells[0].EditedFormattedValue.ToString() == "True")
                {
                    i_consignor = dgv_so_ship_header.Rows[i].Cells["consignor"].Value.ToString().Trim();

                    if (this.cmb_type.Text == "总量拣货")
                        i_wave_no = dgv_so_ship_header.Rows[i].Cells["wave_no"].Value.ToString().Trim();
                    i_so_no = dgv_so_ship_header.Rows[i].Cells["so_no"].Value.ToString().Trim();
                    //s_so_no = "1";
                    //s_so_no = s_so_no + "'" + dgv_so_ship_header.Rows[i].Cells["so_no"].Value.ToString().Trim() + "',";
                    s_consignor = s_consignor + "'" + dgv_so_ship_header.Rows[i].Cells["consignor"].Value.ToString().Trim() + "',";
                    try
                    {
                        if (main.dbtype == "SQL")
                        {
                            if (this.cmb_type.Text == "一单拣货")
                            {
                                s_sql = s_sql + " select 'False' check_uc,a.consignor,ltrim(rtrim(a.so_no)) so_no,a.so_line_no,ltrim(rtrim(a.sku)) sku,b.sku_name,isnull(a.pick_qty_m,0) pick_qty_m,isnull(a.pick_qty_m,0)-isnull(c.box_qty,0) unbox_qty,'0' confirm_qty_m,isnull(c.box_qty,0) box_qty,a.pack_code pack_code,isnull(a.pick_qty_s,0) pick_qty_s,a.order_price order_price,a.order_unit order_unit,isnull(a.pick_cubage,0) pick_cubage,isnull(a.pick_gross_weight,0) pick_gross_weight,isnull(a.pick_net_weight,0) pick_net_weight,a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus,b.gross_weight " +
                                       "from " + main.g_space + ".so_ship_detail a left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku left join" +
                                       "(select so_line_no,sum(isnull(ship_qty_m,0)) box_qty from " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' group by so_line_no) c on a.so_line_no=c.so_line_no " +
                                       "where  a.so_status ='4' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                s_sql_s = s_sql_s + " select 'False' check_uc,a.consignor,ltrim(rtrim(a.so_no)) so_no,a.so_line_no,ltrim(rtrim(a.sku)) sku,b.sku_name,isnull(a.pick_qty_m,0) pick_qty_m,isnull(a.pick_qty_m,0)-isnull(c.box_qty,0) unbox_qty,'0' confirm_qty_m,isnull(c.box_qty,0) box_qty,a.pack_code pack_code,isnull(a.pick_qty_s,0) pick_qty_s,a.order_price order_price,a.order_unit order_unit,isnull(a.pick_cubage,0) pick_cubage,isnull(a.pick_gross_weight,0) pick_gross_weight,isnull(a.pick_net_weight,0) pick_net_weight,a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus,b.gross_weight " +
                                       "from " + main.g_space + ".so_ship_detail a left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku left join" +
                                       "(select so_line_no,sum(isnull(ship_qty_m,0)) box_qty from " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' group by so_line_no) c on a.so_line_no=c.so_line_no " +
                                       "where  a.so_status ='4' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                i_sql_so_pack_header += "  select rtrim(ltrim(a.send_no)) send_no,rtrim(ltrim(a.consignor)) consignor,rtrim(ltrim(a.box_no)) box_no,rtrim(ltrim(a.net_weight)) net_weight,case ltrim(rtrim(a.send_type)) when '' then NULL else a.send_type end send_type,case a.send_type when '0' then b.standby_11 when '1' then b.standby_12 else '' end standby,a.address,rtrim(ltrim(a.spec)) spec,rtrim(ltrim(a.box_size)) box_size,rtrim(ltrim(a.inv_org)) inv_org ,a.memo,a.standby_1 from " + main.g_space + ".so_pack_header a , " + main.g_space + ".so_ship_header b " +
                                            " where a.inv_org = b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no and a.status ='0' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                i_sql_so_pack_header_s += " select  rtrim(ltrim(a.send_no)) send_no,rtrim(ltrim(a.consignor)) consignor,rtrim(ltrim(a.box_no)) box_no,rtrim(ltrim(a.net_weight)) net_weight,case ltrim(rtrim(a.send_type)) when '' then NULL else a.send_type end send_type,case a.send_type when '0' then b.standby_11 when '1' then b.standby_12 else '' end standby,a.address,rtrim(ltrim(a.spec)) spec,rtrim(ltrim(a.box_size)) box_size,rtrim(ltrim(a.inv_org)) inv_org,  a.memo from " + main.g_space + ".so_pack_header a , " + main.g_space + ".so_ship_header b " +
                                        " where a.inv_org = b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no and a.status ='0' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                //i_sql_so_pack_header += " select distinct(rtrim(ltrim(box_no))) box_no,rtrim(ltrim(inv_org)) inv_org,rtrim(ltrim(consignor)) consignor,rtrim(ltrim(spec)) spec,rtrim(ltrim(box_size)) box_size,rtrim(ltrim(net_weight)) net_weight,rtrim(ltrim(send_no)) send_no from " + main.g_space + ".so_pack_header " +
                                //        "where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "'  union";
                                //i_sql_so_pack_header_s += " select distinct(rtrim(ltrim(box_no))) box_no,rtrim(ltrim(inv_org)) inv_org,rtrim(ltrim(consignor)) consignor,rtrim(ltrim(spec)) spec,rtrim(ltrim(box_size)) box_size,rtrim(ltrim(net_weight)) net_weight,rtrim(ltrim(send_no)) send_no from " + main.g_space + ".so_pack_header " +
                                //        "where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' union";
                                i_sql_so_pack_detail += " select a.consignor,a.so_no,a.box_no,a.so_line_no,a.sku,b.sku_name,a.ship_qty_m,b.gross_weight from " + main.g_space + ".so_pack_detail a " +
                                               "left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku " +
                                               "where a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                            }
                            else
                            {
                                s_sql_wave = s_sql_wave + " select 'False' check_uc,a.consignor,ltrim(rtrim(a.so_no)) so_no,a.so_line_no,ltrim(rtrim(a.sku)) sku,b.sku_name,isnull(a.pick_qty_m,0) pick_qty_m,isnull(a.pick_qty_m,0)-isnull(c.box_qty,0) unbox_qty,'0' confirm_qty_m,isnull(c.box_qty,0) box_qty,a.pack_code pack_code,isnull(a.pick_qty_s,0) pick_qty_s,a.order_price order_price,a.order_unit order_unit,isnull(a.pick_cubage,0) pick_cubage,isnull(a.pick_gross_weight,0) pick_gross_weight,isnull(a.pick_net_weight,0) pick_net_weight,a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus,b.gross_weight " +
                                       "from " + main.g_space + ".so_ship_detail a left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku left join" +
                                       "(select so_line_no,sum(isnull(ship_qty_m,0)) box_qty from " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' group by so_line_no) c on a.so_line_no=c.so_line_no " +
                                       "where  a.so_status ='4' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                s_sql_s_wave = s_sql_s_wave + " select 'False' check_uc,a.consignor,ltrim(rtrim(a.so_no)) so_no,a.so_line_no,ltrim(rtrim(a.sku)) sku,b.sku_name,isnull(a.pick_qty_m,0) pick_qty_m,isnull(a.pick_qty_m,0)-isnull(c.box_qty,0) unbox_qty,'0' confirm_qty_m,isnull(c.box_qty,0) box_qty,a.pack_code pack_code,isnull(a.pick_qty_s,0) pick_qty_s,a.order_price order_price,a.order_unit order_unit,isnull(a.pick_cubage,0) pick_cubage,isnull(a.pick_gross_weight,0) pick_gross_weight,isnull(a.pick_net_weight,0) pick_net_weight,a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus,b.gross_weight " +
                                       "from " + main.g_space + ".so_ship_detail a left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku left join" +
                                       "(select so_line_no,sum(isnull(ship_qty_m,0)) box_qty from " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' group by so_line_no) c on a.so_line_no=c.so_line_no " +
                                       "where  a.so_status ='4' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                //s_sql_wave += " select a.wave_no, '0' check_uc,a.consignor,ltrim(rtrim(a.sku)) sku,b.sku_name,isnull(a.pick_qty_m,0) pick_qty_m,isnull(a.pick_qty_m,0)-isnull(c.ship_qty_m,0) unbox_qty,'0' confirm_qty_m,isnull(c.ship_qty_m,0) box_qty,a.pack_code pack_code,isnull(a.pick_qty_s,0) pick_qty_s,a.order_price order_price,a.order_unit order_unit,isnull(a.pick_cubage,0) pick_cubage,isnull(a.pick_gross_weight,0) pick_gross_weight,isnull(a.pick_net_weight,0) pick_net_weight, "+
                                //                "a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus from " + main.g_space + ".mst_sku b, (select sum(ship_qty_m) ship_qty_m,inv_org,consignor,so_no,box_no,sku,so_line_no from " + main.g_space + ".so_pack_detail where so_no = '" + i_wave_no + "' and consignor='"+i_consignor+"' group by inv_org,consignor,so_no,box_no,sku,so_line_no) c, (select wave_no,pack_code,order_price,order_unit,pick_cubage,pick_gross_weight,pick_net_weight, main_sub_flag,convert_modulus,  " +
                                //                "sum(isnull(pick_qty_m,0)) pick_qty_m,sum(isnull(pick_qty_s,0)) pick_qty_s,inv_org,consignor,sku from " + main.g_space + ".so_pick_detail where wave_no = '" + i_wave_no + "'and consignor='"+i_consignor+"' group by inv_org,consignor,sku, wave_no,consignor,sku,pack_code,order_price,order_unit,pick_cubage,pick_gross_weight,pick_net_weight, main_sub_flag,convert_modulus) a  " +
                                //                "where a.inv_org = b.inv_org and a.consignor = b.consignor and a.sku = b.sku and a.inv_org *= c.inv_org and a.consignor *=c.consignor and a.wave_no *= c.so_no and a.sku *= c.sku and a.wave_no ='" + i_wave_no + "' and a.consignor='"+i_consignor+"' union";
                                //s_sql_s_wave += " select a.wave_no, '0' check_uc,a.consignor,ltrim(rtrim(a.sku)) sku,b.sku_name,isnull(a.pick_qty_m,0) pick_qty_m,isnull(a.pick_qty_m,0)-isnull(c.ship_qty_m,0) unbox_qty,'0' confirm_qty_m,isnull(c.ship_qty_m,0) box_qty,a.pack_code pack_code,isnull(a.pick_qty_s,0) pick_qty_s,a.order_price order_price,a.order_unit order_unit,isnull(a.pick_cubage,0) pick_cubage,isnull(a.pick_gross_weight,0) pick_gross_weight,isnull(a.pick_net_weight,0) pick_net_weight, " +
                                //                "a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus from " + main.g_space + ".mst_sku b, (select sum(ship_qty_m) ship_qty_m,inv_org,consignor,so_no,box_no,sku,so_line_no from " + main.g_space + ".so_pack_detail where so_no = '" + i_wave_no + "' and consignor='" + i_consignor + "' group by inv_org,consignor,so_no,box_no,sku,so_line_no) c, (select wave_no,pack_code,order_price,order_unit,pick_cubage,pick_gross_weight,pick_net_weight, main_sub_flag,convert_modulus,  " +
                                //                "sum(isnull(pick_qty_m,0)) pick_qty_m,sum(isnull(pick_qty_s,0)) pick_qty_s,inv_org,consignor,sku from " + main.g_space + ".so_pick_detail where wave_no = '" + i_wave_no + "'and consignor='" + i_consignor + "' group by inv_org,consignor,sku, wave_no,consignor,sku,pack_code,order_price,order_unit,pick_cubage,pick_gross_weight,pick_net_weight, main_sub_flag,convert_modulus) a  " +
                                //                "where a.inv_org = b.inv_org and a.consignor = b.consignor and a.sku = b.sku and a.inv_org *= c.inv_org and a.consignor *=c.consignor and a.wave_no *= c.so_no and a.sku *= c.sku and a.wave_no ='" + i_wave_no + "' and a.consignor='" + i_consignor + "' union";
                                //i_sql_so_pack_header += " select rtrim(ltrim(inv_org)) inv_org,rtrim(ltrim(consignor)) consignor,rtrim(ltrim(box_no)) box_no,rtrim(ltrim(spec)) spec,rtrim(ltrim(box_size)) box_size,rtrim(ltrim(net_weight)) net_weight,case send_type when '0' then '包裹' when '1' then '公路' else '' end send_type,address,rtrim(ltrim(send_no)) send_no " +
                                //                       "from " + main.g_space + ".so_pack_header where status ='0' and inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '"+i_wave_no+"'"+
                                //                       " group by rtrim(ltrim(inv_org)) ,rtrim(ltrim(consignor)) ,rtrim(ltrim(box_no)) ,rtrim(ltrim(spec)),rtrim(ltrim(box_size)),rtrim(ltrim(net_weight)),send_type ,address,rtrim(ltrim(send_no)) union";
                                //i_sql_so_pack_header_s += " select rtrim(ltrim(inv_org)) inv_org,rtrim(ltrim(consignor)) consignor,rtrim(ltrim(box_no)) box_no,rtrim(ltrim(spec)) spec,rtrim(ltrim(box_size)) box_size,rtrim(ltrim(net_weight)) net_weight,case send_type when '0' then '包裹' when '1' then '公路' else '' end send_type,address,rtrim(ltrim(send_no)) send_no " +
                                //                       "from " + main.g_space + ".so_pack_header where status ='0' and inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no ='"+i_wave_no+"'"+
                                //                       " group by rtrim(ltrim(inv_org)) ,rtrim(ltrim(consignor)) ,rtrim(ltrim(box_no)) ,rtrim(ltrim(spec)),rtrim(ltrim(box_size)),rtrim(ltrim(net_weight)),send_type ,address,rtrim(ltrim(send_no)) union";
                                //i_sql_so_pack_detail += " select a.consignor,a.so_no,a.box_no,a.so_line_no,a.sku,b.sku_name,a.ship_qty_m from " + main.g_space + ".so_pack_detail a left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku where a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' " +
                                //                        "and a.so_no ='"+i_wave_no+"'  union";
                                i_sql_so_pack_header += "  select rtrim(ltrim(a.send_no)) send_no,rtrim(ltrim(a.consignor)) consignor,rtrim(ltrim(a.box_no)) box_no,rtrim(ltrim(a.net_weight)) net_weight,a.send_type,case a.send_type when '0' then b.standby_11 when '1' then b.standby_12 else '' end standby,a.address,rtrim(ltrim(a.spec)) spec,rtrim(ltrim(a.box_size)) box_size,rtrim(ltrim(a.inv_org)) inv_org,a.memo,a.standby_1  from " + main.g_space + ".so_pack_header a , " + main.g_space + ".so_ship_header b " +
                                        " where a.inv_org = b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no and a.status ='0' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                i_sql_so_pack_header_s += " select  rtrim(ltrim(a.send_no)) send_no,rtrim(ltrim(a.consignor)) consignor,rtrim(ltrim(a.box_no)) box_no,rtrim(ltrim(a.net_weight)) net_weight,a.send_type,case a.send_type when '0' then b.standby_11 when '1' then b.standby_12 else '' end standby,a.address,rtrim(ltrim(a.spec)) spec,rtrim(ltrim(a.box_size)) box_size,rtrim(ltrim(a.inv_org)) inv_org ,a.memo from " + main.g_space + ".so_pack_header a , " + main.g_space + ".so_ship_header b " +
                                        " where a.inv_org = b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no and a.status ='0' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                                i_sql_so_pack_detail += " select a.consignor,a.so_no,a.box_no,a.so_line_no,a.sku,b.sku_name,a.ship_qty_m,b.gross_weight from " + main.g_space + ".so_pack_detail a " +
                                               "left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku " +
                                               "where a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                            }
                        }
                        else
                        {
                            s_sql = s_sql + " select 'False' check_uc,a.consignor,a.so_no,a.so_line_no,a.sku,b.sku_name,nvl(a.pick_qty_m,0) pick_qty_m,nvl(a.pick_qty_m,0)-nvl(c.box_qty,0) unbox_qty,'0' confirm_qty_m,nvl(c.box_qty,0) box_qty,a.pack_code pack_code,a.pick_qty_s pick_qty_s,a.order_price order_price,a.order_unit order_unit,nvl(a.pick_cubage,0) pick_cubage,nvl(a.pick_gross_weight,0) pick_gross_weight,nvl(a.pick_net_weight,0) pick_net_weight,a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus,b.gross_weight " +
                                  "from " + main.g_space + ".so_ship_detail a left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku left join" +
                                  "(select so_line_no,sum(nvl(ship_qty_m,0)) box_qty from " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' group by so_line_no) c on a.so_line_no=c.so_line_no " +
                                  "where a.so_status ='4' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no ='" + i_so_no + "' union";
                            s_sql_s = s_sql_s + " select 'False' check_uc,a.consignor,a.so_no,a.so_line_no,a.sku,b.sku_name,nvl(a.pick_qty_m,0) pick_qty_m,nvl(a.pick_qty_m,0)-nvl(c.box_qty,0) unbox_qty,'0' confirm_qty_m,nvl(c.box_qty,0) box_qty,a.pack_code pack_code,a.pick_qty_s pick_qty_s,a.order_price order_price,a.order_unit order_unit,nvl(a.pick_cubage,0) pick_cubage,nvl(a.pick_gross_weight,0) pick_gross_weight,nvl(a.pick_net_weight,0) pick_net_weight,a.main_sub_flag main_sub_flag,a.convert_modulus convert_modulus,b.gross_weight " +
                                  "from " + main.g_space + ".so_ship_detail a left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku left join" +
                                  "(select so_line_no,sum(nvl(ship_qty_m,0)) box_qty from " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' group by so_line_no) c on a.so_line_no=c.so_line_no " +
                                  "where a.so_status ='4' and a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no ='" + i_so_no + "' union";
                            i_sql_so_pack_header += " select inv_org,consignor,trim(box_no) box_no,spec,box_size,net_weight,case send_type when '0' then '包裹' when '1' then '公路' else '' end send_type,address,send_no,standby_1 from " + main.g_space + ".so_pack_header " +
                                "where status ='0' and inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' union";
                            i_sql_so_pack_header_s += " select inv_org,consignor,trim(box_no) box_no,spec,box_size,net_weight,case send_type when '0' then '包裹' when '1' then  '公路' else '' end send_type,address,send_no from " + main.g_space + ".so_pack_header " +
                                "where status ='0' and inv_org='" + main.g_org + "' and consignor = '" + i_consignor + "' and so_no = '" + i_so_no + "' union";
                            //i_sql_so_pack_header += " select distinct(trim(box_no)) box_no,inv_org,consignor,spec,box_size,net_weight,send_no from " + main.g_space + ".so_pack_header " +
                            //    "where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + " ' union";
                            //i_sql_so_pack_header_s += " select distinct(trim(box_no)) box_no,inv_org,consignor,spec,box_size,net_weight,send_no from " + main.g_space + ".so_pack_header " +
                            //    "where inv_org='" + main.g_org + "' and consignor = '" + i_consignor + " ' union";
                            i_sql_so_pack_detail += " select a.consignor,a.so_no,a.box_no,a.so_line_no,a.sku,b.sku_name,a.ship_qty_m,b.gross_weight from " + main.g_space + ".so_pack_detail a " +
                                           "left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku " +
                                           "where a.inv_org='" + main.g_org + "' and a.consignor = '" + i_consignor + "' and a.so_no = '" + i_so_no + "' union";
                        }


                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }

                }
            }
            //绑定ship_datail
            if ((s_sql.Length > 0) || (s_sql_wave.Length > 0))
            {
                if (this.cmb_type.Text == "一单拣货")
                {
                    s_sql = s_sql.Substring(0, s_sql.Length - 5) + " order by a.so_line_no";
                    s_sql_s = s_sql_s.Substring(0, s_sql_s.Length - 5) + " order by a.so_line_no";
                }
                else
                    s_sql_wave = s_sql_wave.Substring(0, s_sql_wave.Length - 5) + " order by a.so_no,a.so_line_no,a.sku  ";
                try
                {
                    if (main.dbtype == "SQL")
                    {
                        if (this.cmb_type.SelectedIndex == 0)
                        {
                            ds = main.dbservice.Sql_exec_selectsql(s_sql);
                            ds_s = main.dbservice.Sql_exec_selectsql(s_sql_s);
                        }
                        else
                            ds_wave = main.dbservice.Sql_exec_selectsql(s_sql_wave);
                    }
                    else
                    {
                        ds = main.dbservice.oracle_exec_selectsql(s_sql);
                        ds_s = main.dbservice.oracle_exec_selectsql(s_sql_s);
                    }
                    if (this.cmb_type.SelectedIndex == 0)
                        dgv_so_ship_detail.DataSource = ds.Tables[0];
                    else
                        dgv_so_ship_detail.DataSource = ds_wave.Tables[0];
                    if (dgv_so_ship_detail.Rows.Count > 0)
                    {
                        for (int i = 0; i < dgv_so_ship_detail.Rows.Count; i++)
                        {
                            if (Convert.ToDouble(dgv_so_ship_detail.Rows[i].Cells["unbox_qty"].Value.ToString().Trim()) == 0.0000)
                            {
                                dgv_so_ship_detail.Rows[i].DefaultCellStyle.BackColor = Color.LightGreen;
                            }
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ex.ToString());
                    return;
                }
            }
            else
            {
                if (dgv_so_ship_detail.Rows.Count > 0)
                {
                    DataTable dt = new DataTable();
                    //清空so_pack_detail
                    dt = dgv_so_ship_detail.DataSource as DataTable;
                    dt.Rows.Clear();
                    dgv_so_ship_detail.DataSource = dt;
                }
            }

            //绑定so_pack_header
            if (i_sql_so_pack_header.Length > 0)
            {
                i_sql_so_pack_header = i_sql_so_pack_header.Substring(0, i_sql_so_pack_header.Length - 5);
                i_sql_so_pack_header_s = i_sql_so_pack_header_s.Substring(0, i_sql_so_pack_header_s.Length - 5);
                try
                {
                    if (main.dbtype == "SQL")
                    {
                        i_ds_so_pack_header = main.dbservice.Sql_exec_selectsql(i_sql_so_pack_header);
                        i_ds_so_pack_header_s = main.dbservice.Sql_exec_selectsql(i_sql_so_pack_header_s);
                    }
                    else
                    {
                        i_ds_so_pack_header = main.dbservice.oracle_exec_selectsql(i_sql_so_pack_header);
                        i_ds_so_pack_header_s = main.dbservice.oracle_exec_selectsql(i_sql_so_pack_header);
                    }
                    dgv_so_pack_header.DataSource = i_ds_so_pack_header.Tables[0];
                    if (i_ds_so_pack_header.Tables[0].Rows.Count > 0)
                    {
                        btn_print.Enabled = true;
                    }
                    else
                    {
                        btn_print.Enabled = false;
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ex.ToString());
                    return;
                }

            }
            else
            {
                if (dgv_so_pack_header.Rows.Count > 0)
                {
                    DataTable dt = new DataTable();
                    //清空so_pack_detail
                    dt = dgv_so_pack_header.DataSource as DataTable;
                    dt.Rows.Clear();
                    dgv_so_pack_header.DataSource = dt;
                    btn_print.Enabled = false;
                }
            }

            //绑定so_pack_detail
            if (i_sql_so_pack_detail.Length > 0)
            {
                i_sql_so_pack_detail = i_sql_so_pack_detail.Substring(0, i_sql_so_pack_detail.Length - 5);
                try
                {
                    if (main.dbtype == "SQL")
                    {
                        i_ds_so_pack_detail = main.dbservice.Sql_exec_selectsql(i_sql_so_pack_detail);
                    }
                    else
                    {
                        i_ds_so_pack_detail = main.dbservice.oracle_exec_selectsql(i_sql_so_pack_detail);
                    }
                    dgv_so_pack_detail.DataSource = i_ds_so_pack_detail.Tables[0];
                    if (i_ds_so_pack_detail.Tables[0].Rows.Count > 0)
                        btn_detail_print.Enabled = true;
                    else
                        btn_detail_print.Enabled = false;
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ee.ToString());
                    return;
                }
            }
            else
            {
                if (dgv_so_pack_detail.Rows.Count > 0)
                {
                    btn_detail_print.Enabled = false;
                    DataTable dt = new DataTable();
                    //清空so_pack_detail
                    dt = dgv_so_pack_detail.DataSource as DataTable;
                    dt.Rows.Clear();
                    dgv_so_pack_detail.DataSource = dt;
                }
            }
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_subnew_Click(object sender, EventArgs e)
        {
            if (dgv_so_ship_header.CurrentRow != null)
            {
                //弹出新对话框
                w_so019_add new_win = new w_so019_add();
                w_so019_add.consignor = dgv_so_ship_header.CurrentRow.Cells["consignor"].Value.ToString().Trim();
                w_so019_add.so_no = dgv_so_ship_header.CurrentRow.Cells["so_no"].Value.ToString().Trim();
                //if (this.cmb_type.SelectedIndex == 1)
                //{
                //    w_so019_add.wave_no = dgv_so_ship_header.CurrentRow.Cells["wave_no"].Value.ToString().Trim();
                //}
                w_so019_add.i_dist = 1;
                if (new_win.ShowDialog() == DialogResult.OK)
                {
                    so_bind();
                }
            }
            else
            {
                MessageBox.Show("请选择要装箱的订单！");
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_submodi_Click(object sender, EventArgs e)
        {
            //有数据
            if (dgv_so_pack_header.CurrentRow != null)
            {
                //弹出新对话框
                w_so019_add new_win = new w_so019_add();
                w_so019_add.consignor = dgv_so_ship_header.CurrentRow.Cells["consignor"].Value.ToString().Trim();
                w_so019_add.so_no = dgv_so_ship_header.CurrentRow.Cells["so_no"].Value.ToString().Trim();
                w_so019_add.wave_no = dgv_so_ship_header.CurrentRow.Cells["wave_no"].Value.ToString().Trim();
                //if (this.cmb_type.SelectedIndex == 1)
                //{
                //    w_so019_add.wave_no = dgv_so_ship_header.CurrentRow.Cells["wave_no"].Value.ToString().Trim();
                //}
                w_so019_add.i_dist = 2;
                new_win.ShowDialog();

                so_bind();
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_subdel_Click(object sender, EventArgs e)
        {
            if (dgv_so_pack_header.CurrentRow != null)
            {
                string[] array_sql = new string[2];
                array_sql[0] = "delete " + main.g_space + ".so_pack_header where status ='0' and inv_org='" + main.g_org + "' " +
                               "and consignor='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString() + "' " +
                    //"and so_no='" + dgv_so_pack_header.CurrentRow.Cells["so_no_so_pack_header"].Value.ToString() + "' " +
                               "and box_no='" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString() + "'";

                array_sql[1] = "delete " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' " +
                               "and consignor='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString() + "' " +
                               "and box_no='" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString() + "'";


                //提示
                if (MessageBox.Show(main.g_class.comm_getchangestring("Are you sure to delete box", main.g_info_dataset) + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "?", main.g_class.comm_getchangestring("Information", main.g_info_dataset), MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    try
                    {
                        if (main.dbtype == "SQL")
                        {
                            main.dbservice.Sql_exec_mutilsql(array_sql);
                        }
                        else
                        {
                            main.dbservice.oracle_exec_mutilsql(array_sql);
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to delete box", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                }
                //重新绑定
                so_bind();
            }
        }

        private void btn_subsave_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dgv_so_pack_header.Rows.Count; i++)
            {
                //判断重量是否发生变化，如果变化了就update
                if ((i_ds_so_pack_header_s.Tables[0].Rows[i]["net_weight"].ToString().Trim() != dgv_so_pack_header.Rows[i].Cells["net_weight_so_pack_header"].Value.ToString().Trim()) || (i_ds_so_pack_header_s.Tables[0].Rows[i]["send_type"].ToString().Trim() != dgv_so_pack_header.Rows[i].Cells["send_type_so_pack_header"].Value.ToString().Trim()) || (i_ds_so_pack_header_s.Tables[0].Rows[i]["address"].ToString().Trim() != dgv_so_pack_header.Rows[i].Cells["address_so_pack_header"].Value.ToString().Trim()) || (i_ds_so_pack_header_s.Tables[0].Rows[i]["memo"].ToString().Trim() != dgv_so_pack_header.Rows[i].Cells["memo"].Value.ToString().Trim()))
                {
                    string str_wave;
                    if (dgv_so_ship_header.Rows[dgv_so_ship_header.CurrentRow.Index].Cells["wave_no"].Value == null)
                    {
                        str_wave = "0";
                    }
                    else
                    {
                        str_wave = dgv_so_ship_header.Rows[dgv_so_ship_header.CurrentRow.Index].Cells["wave_no"].Value.ToString().Trim();
                    }
                     
                    string i_net_weight;
                    if (dgv_so_pack_header.Rows[i].Cells["net_weight_so_pack_header"].Value.ToString().Trim() != "")
                        i_net_weight = dgv_so_pack_header.Rows[i].Cells["net_weight_so_pack_header"].Value.ToString().Trim();
                    else
                        i_net_weight = "0";
                    try
                    {
                        if (main.dbtype == "SQL")
                        {

                            String str_sql = "update " + main.g_space + ".so_pack_header set address ='" + dgv_so_pack_header.Rows[i].Cells["address_so_pack_header"].Value.ToString().Trim() + "', send_type='" + dgv_so_pack_header.Rows[i].Cells["send_type_so_pack_header"].Value.ToString().Trim() + "', main_dist ='C',update_time =getdate(),updater='" + main.g_username + "', net_weight ='" + i_net_weight +
                                            "',memo ='" + dgv_so_pack_header.Rows[i].Cells["memo"].Value.ToString().Trim() + "' where status='0' and inv_org ='" + dgv_so_pack_header.Rows[i].Cells["inv_org_so_pack_header"].Value.ToString().Trim() +
                                            "' and consignor ='" + dgv_so_pack_header.Rows[i].Cells["consignor_so_pack_header"].Value.ToString().Trim() +
                                            "' and box_no ='" + dgv_so_pack_header.Rows[i].Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'";
                            str_sql += " and so_no in (select so_no from " + main.g_space + ".so_ship_wavedetail where inv_org='" + main.g_org + "' and consignor='" + dgv_so_pack_header.Rows[i].Cells["consignor_so_pack_header"].Value.ToString().Trim() + "' and wave_no='" + str_wave + "') ";
                            main.dbservice.Sql_exec_commandsql(str_sql);
                        }
                        else
                        {
                            String str_sql = "update " + main.g_space + ".so_pack_header set address ='" + dgv_so_pack_header.Rows[i].Cells["address_so_pack_header"].Value.ToString().Trim() + "', send_type='" + dgv_so_pack_header.Rows[i].Cells["send_type_so_pack_header"].Value.ToString().Trim() + "', main_dist ='C',update_time =sysdate,updater='" + main.g_username + "', net_weight ='" + i_net_weight +
                                            "',memo ='" + dgv_so_pack_header.Rows[i].Cells["memo"].Value.ToString().Trim() + "' where status='0' and inv_org ='" + dgv_so_pack_header.Rows[i].Cells["inv_org_so_pack_header"].Value.ToString().Trim() +
                                            "' and consignor ='" + dgv_so_pack_header.Rows[i].Cells["consignor_so_pack_header"].Value.ToString().Trim() +
                                            "' and box_no ='" + dgv_so_pack_header.Rows[i].Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'";
                            str_sql += " and so_no in (select so_no from " + main.g_space + ".so_ship_wavedetail where inv_org='" + main.g_org + "' and consignor='" + dgv_so_pack_header.Rows[i].Cells["consignor_so_pack_header"].Value.ToString().Trim() + "' and wave_no='" + str_wave + "') ";
                            main.dbservice.oracle_exec_commandsql(str_sql);
                        }

                    }
                    catch (Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Failed!", main.g_info_dataset) + ee.ToString());
                        return;
                    }
                }
            }
            so_bind();
            MessageBox.Show(main.g_class.comm_getchangestring("修改成功", main.g_info_dataset) + "!");
        }

        private void btn_print_Click(object sender, EventArgs e)
        {
            //int i = dgv_so_pack_header.CurrentRow.Index;
            string box_no_i = " ";
            string str_sql=" ";
            for (int i = 0; i < dgv_so_pack_header.Rows.Count; i++)
            {
                if ((bool)dgv_so_pack_header.Rows[i].Cells["checkboxHeader"].EditedFormattedValue)
                {
                    if (i_ds_so_pack_header_s.Tables[0].Rows[i]["send_type"].ToString().Trim() == "")
                    {
                        MessageBox.Show("请选择发运方式并保存!");
                        return;
                    }
                    if (i_ds_so_pack_header_s.Tables[0].Rows[i]["net_weight"].ToString().Trim() == "")
                    {
                        MessageBox.Show("请确认箱子重量并保存!");
                        return;
                    }
                    box_no_i += "'" + dgv_so_pack_header.Rows[i].Cells["box_no_so_pack_header"].Value.ToString().Trim() + "',";
                    str_sql += " select top 1 '" + main.g_username + "' maker,rtrim(ltrim(box_no)) plu_code,a.net_weight,a.box_size spec,case b.so_type when '5' then b.so_no else a.send_no end send_no,a.memo,b.customer_name,b.customer_code,case ltrim(rtrim(b.address)) when '' then c.clerk else b.receiver end receiver,case ltrim(rtrim(b.address)) when '' then c.telephone else b.telephone end telephone,a.address  from " + main.g_space + ".so_pack_header a ," + main.g_space + ".so_ship_header b," + main.g_space + ".mst_customer c " +
                                 " where b.inv_org *= c.inv_org and b.customer_code *= c.consignor and b.customer_name *= c.consignor_name and a.inv_org =b.inv_org and a.consignor =b.consignor and a.so_no = b.so_no and status='0' " +
                                 " and a.inv_org='" + dgv_so_pack_header.Rows[i].Cells["inv_org_so_pack_header"].Value.ToString().Trim() +
                                 "' and a.consignor='" + dgv_so_pack_header.Rows[i].Cells["consignor_so_pack_header"].Value.ToString().Trim() +
                                 "' and a.box_no='" + dgv_so_pack_header.Rows[i].Cells["box_no_so_pack_header"].Value.ToString().Trim() + "' union";
                }
            }

            if (str_sql.Trim() == "")
            {
                MessageBox.Show("请选择要打印的箱单!");
                return;
            }


            ds_system_s = new DataSet();

                try
                {

                    if (main.dbtype == "SQL")
                    {
                        str_sql = str_sql.Trim().Substring(0, str_sql.Trim().Length - 5);
                        ds_system_s = main.dbservice.Sql_exec_selectsql(str_sql);
                    }
                    else
                    {
                        str_sql = str_sql.Trim().Substring(0, str_sql.Trim().Length - 5);
                        ds_system_s = main.dbservice.oracle_exec_selectsql(str_sql);
                    }
                    ds_system_s.Tables[0].Columns.Add("image", System.Type.GetType("System.Byte[]"));

                    ds_system_s.Tables[0].Columns.Add("so_no", System.Type.GetType("System.String"));
                    if (ds_system_s.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < ds_system_s.Tables[0].Rows.Count; i++)
                        {
                            if (ds_system_s.Tables[0].Rows[i]["plu_code"].ToString().Trim() != "")
                            {
                                b_bar.IncludeLabel = true;
                                b_bar.Encode(BarcodeLib.TYPE.CODE128, ds_system_s.Tables[0].Rows[i]["plu_code"].ToString().Trim(), System.Drawing.Color.Black, System.Drawing.Color.White, 420, 60);
                                byte[] byteArray = b_bar.GetImageData(BarcodeLib.SaveTypes.PNG);
                                ds_system_s.Tables[0].Rows[i]["image"] = byteArray;//将图片存储到dataSet中 
                            }

                            if (this.cmb_type.SelectedIndex == 1)
                            {
                                string i_wave_no = dgv_so_ship_header.CurrentRow.Cells["wave_no"].Value.ToString().Trim();

                                ds_system_s.Tables[0].Rows[i]["so_no"] = i_wave_no;
                            }
                            if (ds_system_s.Tables[0].Rows.Count > 0)
                            {
                                btn_print.Enabled = true;
                            }
                            else
                            {
                                btn_print.Enabled = false;
                            }

                            try
                            {
                                this.so019_rept1.SetDataSource(ds_system_s.Tables[0]);
                                this.crystalReportViewer1.ReportSource = so019_rept1;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                                return;
                            }
                        }
                    }
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message);
                    return;
                }


                crystalReportViewer1.PrintReport();
                box_no_i = box_no_i.Trim().Substring(0, box_no_i.Trim().Length - 1);
                try
                {
                    if (main.dbtype == "SQL")
                    {
                        String str_sql2 = "update " + main.g_space + ".so_pack_header set main_dist ='C',update_time =getdate(),updater='" + main.g_username + "', ship_day ='" + DateTime.Now.ToString("yyyy.MM.dd").Trim() + "', standby_1 ='1'" +
                            " where status ='0' and inv_org ='" + dgv_so_pack_header.CurrentRow.Cells["inv_org_so_pack_header"].Value.ToString().Trim() +
                            "' and consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() +
                            "' and box_no in (" + box_no_i + ")";
                        main.dbservice.Sql_exec_commandsql(str_sql2);
                    }
                    else
                    {
                        String str_sql2 = "update " + main.g_space + ".so_pack_header set main_dist ='C',update_time =sysdate,updater='" + main.g_username + "', ship_day ='" + DateTime.Now.ToString("yyyy.MM.dd").Trim() + "', standby_1 ='1'" +
                            " where status ='0' and inv_org ='" + dgv_so_pack_header.CurrentRow.Cells["inv_org_so_pack_header"].Value.ToString().Trim() +
                            "' and consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() +
                            "' and box_no in (" + box_no_i + ")";
                        main.dbservice.oracle_exec_commandsql(str_sql2);
                    }


                }
                catch (Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Failed!", main.g_info_dataset) + ee.ToString());
                    return;
                }            
        }


        /// <summary>
        /// 绑定出库单装箱明细so_pack_detail
        /// </summary>
        /// <param name="consignor"></param>
        /// <param name="so_no"></param>
        /// <param name="box_no"></param>
        private void f_Bind_so_pack_detail(string consignor, string so_no, string box_no)
        {
            DataSet ds = new DataSet();
            string s_sql = "select a.consignor,a.so_no,a.box_no,a.so_line_no,a.sku,b.sku_name,a.ship_qty_m from " + main.g_space + ".so_pack_detail a " +
                           "left join " + main.g_space + ".mst_sku b on a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku " +
                           "where a.inv_org='" + main.g_org + "' and a.consignor in ('" + consignor + "') and a.so_no in ('" + so_no + "') ";
            if (!string.IsNullOrEmpty(box_no))
            {
                s_sql += " and a.box_no='" + box_no + "'";
            }
            try
            {
                if (main.dbtype == "SQL")
                {
                    ds = main.dbservice.Sql_exec_selectsql(s_sql);
                }
                else
                {
                    ds = main.dbservice.oracle_exec_selectsql(s_sql);
                }
                dgv_so_pack_detail.DataSource = ds.Tables[0];
                if (ds.Tables[0].Rows.Count > 0)
                    this.btn_detail_print.Enabled = true;
                else
                    this.btn_detail_print.Enabled = false;
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }
        }

        private void txt_add_sku_KeyPress(object sender, KeyPressEventArgs e)
        {
            //int i_count = 0;
            int i_sku_count = 0;
            int i_check_count = 0;
            int i_same_count = 0;
            DataSet ds_count = new DataSet();
            DataSet ds_header_count = new DataSet();
            string i_so_no = "";
            //string i_wave_no = "";
            string i_so_line_no = "";
            string s_pack_sql = "";
            string i_in_header_sql = "";
            string i_sku = "";
            string i_pack_code = "";
            string i_pick_qty_s = "";
            string i_order_price = "";
            string i_order_unit = "";
            string i_pick_cubage = "";
            string i_pick_gross_weight = "";
            string i_pick_net_weight = "";
            string i_main_sub_flag = "";
            string i_convert_modulus = "";
            decimal confirm_qty_m = 0;
            decimal unbox_qty = 0;
            if (this.dgv_so_pack_header.Rows.Count < 1)
            {
                MessageBox.Show("请新增一个箱子!");
                return;
            }


            #region 一单拣货
            //if (this.cmb_type.SelectedIndex == 0)
            //{
            if (dgv_so_ship_detail.Rows.Count > 0)
            {

                if (e.KeyChar == 13)
                {
                    int i_rowIndex = dgv_so_pack_header.CurrentRow.Index;
                    for (int k = 0; k < dgv_so_ship_detail.Rows.Count; k++)
                    {
                        if ((txt_add_sku.Text.ToString().Trim() == dgv_so_ship_detail.Rows[k].Cells["sku"].Value.ToString().Trim()) && (dgv_so_ship_detail.Rows[k].Cells["check_uc"].Value.ToString().Trim() == "True") && (dgv_so_ship_detail.Rows[k].Cells["so_ship_consignor"].Value.ToString().Trim() == dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim()))
                        {
                            i_same_count++;
                        }
                        if (dgv_so_ship_detail.Rows[k].Cells["check_uc"].Value.ToString().Trim() == "True")
                        {
                            i_check_count++;
                        }
                        if ((txt_add_sku.Text.ToString().Trim() == dgv_so_ship_detail.Rows[k].Cells["sku"].Value.ToString().Trim()) && (dgv_so_ship_detail.Rows[k].Cells["so_ship_consignor"].Value.ToString().Trim() == dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim()))
                        {
                            i_sku_count++;
                        }
                        //if (dgv_so_ship_detail.Rows[k].Cells["so_ship_consignor"].Value.ToString().Trim() == dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim())
                        //{
                        //    i_count++;
                        //}                          
                    }
                    if ((i_same_count > 1) || (i_check_count == 0 && i_sku_count > 1))
                    {
                        MessageBox.Show("请选择要装箱的制定出库单商品");
                        return;
                    }
                    else if (i_same_count == 1)
                    {
                        for (int r = 0; r < dgv_so_ship_detail.Rows.Count; r++)
                        {
                            if ((txt_add_sku.Text.ToString().Trim() == dgv_so_ship_detail.Rows[r].Cells["sku"].Value.ToString().Trim()) && (dgv_so_ship_detail.Rows[r].Cells["check_uc"].Value.ToString().Trim() == "True") && (dgv_so_ship_detail.Rows[r].Cells["so_ship_consignor"].Value.ToString().Trim() == dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim()))
                            {
                                if (this.cmb_type.SelectedIndex == 0)
                                {
                                    confirm_qty_m = Convert.ToDecimal(ds_s.Tables[0].Rows[r]["confirm_qty_m"].ToString().Trim());

                                    unbox_qty = Convert.ToDecimal(ds_s.Tables[0].Rows[r]["unbox_qty"].ToString().Trim());
                                }
                                else
                                {

                                    confirm_qty_m = Convert.ToDecimal(ds_wave_s.Tables[0].Rows[r]["confirm_qty_m"].ToString().Trim());

                                    unbox_qty = Convert.ToDecimal(ds_wave_s.Tables[0].Rows[r]["unbox_qty"].ToString().Trim());
                                }
                                //判断数量是否超
                                if (confirm_qty_m >= unbox_qty)
                                {
                                    MessageBox.Show("装箱数量不能大于剩余数量");
                                    return;
                                }
                                i_so_no = dgv_so_ship_detail.Rows[r].Cells["so_no_ship_detail"].Value.ToString().Trim();
                                i_so_line_no = dgv_so_ship_detail.Rows[r].Cells["so_line_no"].Value.ToString().Trim();
                                i_sku = dgv_so_ship_detail.Rows[r].Cells["sku"].Value.ToString().Trim();
                                i_pack_code = dgv_so_ship_detail.Rows[r].Cells["pack_code"].Value.ToString().Trim();
                                i_pick_qty_s = dgv_so_ship_detail.Rows[r].Cells["pick_qty_s"].Value.ToString().Trim();
                                i_order_price = dgv_so_ship_detail.Rows[r].Cells["order_price"].Value.ToString().Trim();
                                i_order_unit = dgv_so_ship_detail.Rows[r].Cells["order_unit"].Value.ToString().Trim();
                                i_pick_cubage = dgv_so_ship_detail.Rows[r].Cells["pick_cubage"].Value.ToString().Trim();
                                i_pick_gross_weight = dgv_so_ship_detail.Rows[r].Cells["pick_gross_weight"].Value.ToString().Trim();
                                i_pick_net_weight = dgv_so_ship_detail.Rows[r].Cells["pick_net_weight"].Value.ToString().Trim();
                                i_main_sub_flag = dgv_so_ship_detail.Rows[r].Cells["main_sub_flag"].Value.ToString().Trim();
                                i_convert_modulus = dgv_so_ship_detail.Rows[r].Cells["convert_modulus"].Value.ToString().Trim();
                            }
                        }

                    }
                    else if (i_check_count == 1)
                    {
                        for (int r = 0; r < dgv_so_ship_detail.Rows.Count; r++)
                        {
                            if (dgv_so_ship_detail.Rows[r].Cells["check_uc"].Value.ToString().Trim() == "True")
                            {
                                if (this.cmb_type.SelectedIndex == 0)
                                {
                                    confirm_qty_m = Convert.ToDecimal(ds_s.Tables[0].Rows[r]["confirm_qty_m"].ToString().Trim());

                                    unbox_qty = Convert.ToDecimal(ds_s.Tables[0].Rows[r]["unbox_qty"].ToString().Trim());
                                }
                                else
                                {
                                    confirm_qty_m = Convert.ToDecimal(ds_wave_s.Tables[0].Rows[r]["confirm_qty_m"].ToString().Trim());

                                    unbox_qty = Convert.ToDecimal(ds_wave_s.Tables[0].Rows[r]["unbox_qty"].ToString().Trim());
                                }
                                //判断数量是否超
                                if (confirm_qty_m >= unbox_qty)
                                {
                                    MessageBox.Show("装箱数量不能大于剩余数量");
                                    return;
                                }
                                i_so_no = dgv_so_ship_detail.Rows[r].Cells["so_no_ship_detail"].Value.ToString().Trim();
                                i_so_line_no = dgv_so_ship_detail.Rows[r].Cells["so_line_no"].Value.ToString().Trim();
                                i_sku = dgv_so_ship_detail.Rows[r].Cells["sku"].Value.ToString().Trim();
                                i_pack_code = dgv_so_ship_detail.Rows[r].Cells["pack_code"].Value.ToString().Trim();
                                i_pick_qty_s = dgv_so_ship_detail.Rows[r].Cells["pick_qty_s"].Value.ToString().Trim();
                                i_order_price = dgv_so_ship_detail.Rows[r].Cells["order_price"].Value.ToString().Trim();
                                i_order_unit = dgv_so_ship_detail.Rows[r].Cells["order_unit"].Value.ToString().Trim();
                                i_pick_cubage = dgv_so_ship_detail.Rows[r].Cells["pick_cubage"].Value.ToString().Trim();
                                i_pick_gross_weight = dgv_so_ship_detail.Rows[r].Cells["pick_gross_weight"].Value.ToString().Trim();
                                i_pick_net_weight = dgv_so_ship_detail.Rows[r].Cells["pick_net_weight"].Value.ToString().Trim();
                                i_main_sub_flag = dgv_so_ship_detail.Rows[r].Cells["main_sub_flag"].Value.ToString().Trim();
                                i_convert_modulus = dgv_so_ship_detail.Rows[r].Cells["convert_modulus"].Value.ToString().Trim();
                            }
                        }
                    }
                    else if (i_check_count == 0 && i_sku_count == 1)
                    {
                        for (int r = 0; r < dgv_so_ship_detail.Rows.Count; r++)
                        {
                            if ((txt_add_sku.Text.ToString().Trim() == dgv_so_ship_detail.Rows[r].Cells["sku"].Value.ToString().Trim()) && (dgv_so_ship_detail.Rows[r].Cells["so_ship_consignor"].Value.ToString().Trim() == dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim()))
                            {
                                if (this.cmb_type.SelectedIndex == 0)
                                {
                                    confirm_qty_m = Convert.ToDecimal(ds_s.Tables[0].Rows[r]["confirm_qty_m"].ToString().Trim());

                                    unbox_qty = Convert.ToDecimal(ds_s.Tables[0].Rows[r]["unbox_qty"].ToString().Trim());
                                }
                                else
                                {
                                    confirm_qty_m = Convert.ToDecimal(ds_wave_s.Tables[0].Rows[r]["confirm_qty_m"].ToString().Trim());

                                    unbox_qty = Convert.ToDecimal(ds_wave_s.Tables[0].Rows[r]["unbox_qty"].ToString().Trim());
                                }
                                //判断数量是否超
                                if (confirm_qty_m >= unbox_qty)
                                {
                                    MessageBox.Show("装箱数量不能大于剩余数量");
                                    return;
                                }
                                i_so_no = dgv_so_ship_detail.Rows[r].Cells["so_no_ship_detail"].Value.ToString().Trim();
                                i_so_line_no = dgv_so_ship_detail.Rows[r].Cells["so_line_no"].Value.ToString().Trim();
                                i_sku = dgv_so_ship_detail.Rows[r].Cells["sku"].Value.ToString().Trim();
                                i_pack_code = dgv_so_ship_detail.Rows[r].Cells["pack_code"].Value.ToString().Trim();
                                i_pick_qty_s = dgv_so_ship_detail.Rows[r].Cells["pick_qty_s"].Value.ToString().Trim();
                                i_order_price = dgv_so_ship_detail.Rows[r].Cells["order_price"].Value.ToString().Trim();
                                i_order_unit = dgv_so_ship_detail.Rows[r].Cells["order_unit"].Value.ToString().Trim();
                                i_pick_cubage = dgv_so_ship_detail.Rows[r].Cells["pick_cubage"].Value.ToString().Trim();
                                i_pick_gross_weight = dgv_so_ship_detail.Rows[r].Cells["pick_gross_weight"].Value.ToString().Trim();
                                i_pick_net_weight = dgv_so_ship_detail.Rows[r].Cells["pick_net_weight"].Value.ToString().Trim();
                                i_main_sub_flag = dgv_so_ship_detail.Rows[r].Cells["main_sub_flag"].Value.ToString().Trim();
                                i_convert_modulus = dgv_so_ship_detail.Rows[r].Cells["convert_modulus"].Value.ToString().Trim();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("此箱子已被其他货主占用");
                        return;
                    }
                    //判断有箱子
                    if (dgv_so_pack_header.Rows.Count <= 0)
                    {
                        MessageBox.Show("请先增加一个箱子");
                        return;
                    }
                    string str_sql = "select * from " + main.g_space + ".so_pack_detail where inv_org ='" + main.g_org + "' and " +
                                    "consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "' and " +
                                    "so_no = '" + i_so_no + "' and box_no = '" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'and " +
                                    "so_line_no ='" + i_so_line_no + "'";
                    string str_sql_pack_header = "select * from " + main.g_space + ".so_pack_header where status ='0' and inv_org ='" + main.g_org + "' and " +
                                    "consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "' and " +
                                    "so_no = '" + i_so_no + "' and box_no = '" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'";
                    if (main.dbtype == "SQL")
                    {
                        ds_count = main.dbservice.Sql_exec_selectsql(str_sql);
                        ds_header_count = main.dbservice.Sql_exec_selectsql(str_sql_pack_header);
                    }
                    else
                    {
                        ds_count = main.dbservice.oracle_exec_selectsql(str_sql);
                        ds_header_count = main.dbservice.Sql_exec_selectsql(str_sql_pack_header);
                    }
                    if (ds_header_count.Tables[0].Rows.Count == 0)
                    {
                        string i_net_werght;
                        if (dgv_so_pack_header.CurrentRow.Cells["net_weight_so_pack_header"].Value.ToString().Trim() == "")
                        {
                            i_net_werght = "null";
                        }
                        else
                        {
                            i_net_werght = dgv_so_pack_header.CurrentRow.Cells["net_weight_so_pack_header"].Value.ToString().Trim();
                        }
                        if (main.dbtype == "SQL")
                        {
                            //i_in_header_sql = "insert into " + main.g_space + ".so_pack_header (inv_org,consignor,so_no,box_no,spec,box_size,net_weight,send_no,status,memo,main_dist,made_time,maker) values ( '" +
                            //        main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "','" +
                            //        i_so_no + "','" +
                            //        dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "','" +
                            //        dgv_so_pack_header.CurrentRow.Cells["spec_so_pack_header"].Value.ToString().Trim() + "','" +
                            //        dgv_so_pack_header.CurrentRow.Cells["box_size_so_pack_header"].Value.ToString().Trim() + "'," +
                            //        i_net_werght + ",'" +
                            //        dgv_so_pack_header.CurrentRow.Cells["send_no_so_pack_header"].Value.ToString().Trim() + "','0','','A',getdate(),'" + main.g_username + "')";
                            i_in_header_sql = "insert into wms.so_pack_header ([inv_org],[consignor],[so_no],[box_no],[spec],[box_size],[net_weight],[send_no],[carrier],[carrier_address],[carrier_postalcode],[carrier_phone],[ship_no],[fly_no],[vehicle_no],[standby_1],[standby_2],[standby_3],[standby_4],[standby_5],[standby_6],[standby_7],[memo],[main_dist],[made_time],[maker],[status]" +
                                             ",[ship_day],[shipper],[address],[send_type])  select top 1 [inv_org],[consignor],'" + i_so_no + "',[box_no],[spec],[box_size],[net_weight],[send_no],[carrier],[carrier_address],[carrier_postalcode],[carrier_phone],[ship_no],[fly_no],[vehicle_no],[standby_1],[standby_2],[standby_3],[standby_4],[standby_5],[standby_6],[standby_7],[memo],'A',getdate(),'" + main.g_user + "',[status]" +
                                             ",[ship_day],[shipper],[address],[send_type] from wms.so_pack_header where inv_org = '" + main.g_org + "' and consignor = '" + dgv_so_ship_header.CurrentRow.Cells["consignor"].Value.ToString().Trim() + "' and box_no ='" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'";
                        }
                        else
                        {
                            i_in_header_sql = "insert into " + main.g_space + ".so_pack_header (inv_org,consignor,so_no,box_no,spec,box_size,net_weight,send_no,status,memo,main_dist,made_time,maker) values ( '" +
                                        main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "','" +
                                        i_so_no + "','" +
                                        dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "','" +
                                        dgv_so_pack_header.CurrentRow.Cells["spec_so_pack_header"].Value.ToString().Trim() + "','" +
                                        dgv_so_pack_header.CurrentRow.Cells["box_size_so_pack_header"].Value.ToString().Trim() + "'," +
                                        i_net_werght + ",'" +
                                        dgv_so_pack_header.CurrentRow.Cells["send_no_so_pack_header"].Value.ToString().Trim() + "','0','','A',sysdate,'" + main.g_username + "')";
                        }
                    }
                    if (ds_count.Tables[0].Rows.Count == 0)
                    {
                        try
                        {
                            if (main.dbtype == "SQL")
                            {
                                s_pack_sql = "insert into " + main.g_space + ".so_pack_detail(inv_org,consignor,so_no,box_no,so_line_no,sku,ship_qty_m,pack_code,ship_qty_s,order_price,order_unit,ship_cubage,ship_gross_weight,ship_net_weight,main_sub_flag,convert_modulus,main_dist,made_time,maker) " +
                                           "values('" + main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "'," +
                                           "'" + i_so_no + "'," +
                                           "'" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'," +
                                           "'" + i_so_line_no + "'," +
                                           "'" + i_sku + "'," +
                                           "'1'," +
                                           "'" + i_pack_code + "'," +
                                           "'" + i_pick_qty_s + "'," +
                                           "'" + i_order_price + "'," +
                                           "'" + i_order_unit + "'," +
                                           "'" + i_pick_cubage + "'," +
                                           "'" + i_pick_gross_weight + "'," +
                                           "'" + i_pick_net_weight + "'," +
                                           "'" + i_main_sub_flag + "'," +
                                           "'" + i_convert_modulus +
                                           "','A',getdate(),'" + main.g_username + "')";
                                main.dbservice.Sql_exec_commandsql(s_pack_sql);
                            }
                            else
                            {
                                s_pack_sql = "insert into " + main.g_space + ".so_pack_detail(inv_org,consignor,so_no,box_no,so_line_no,sku,ship_qty_m,pack_code,ship_qty_s,order_price,order_unit,ship_cubage,ship_gross_weight,ship_net_weight,main_sub_flag,convert_modulus,main_dist,made_time,maker) " +
                                           "values('" + main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "'," +
                                           "'" + i_so_no + "'," +
                                           "'" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'," +
                                           "'" + i_so_line_no + "'," +
                                           "'" + i_sku + "'," +
                                           "'1'," +
                                           "'" + i_pack_code + "'," +
                                           "'" + i_pick_qty_s + "'," +
                                           "'" + i_order_price + "'," +
                                           "'" + i_order_unit + "'," +
                                           "'" + i_pick_cubage + "'," +
                                           "'" + i_pick_gross_weight + "'," +
                                           "'" + i_pick_net_weight + "'," +
                                           "'" + i_main_sub_flag + "'," +
                                           "'" + i_convert_modulus +
                                           "','A',sysdate,'" + main.g_username + "')";
                                main.dbservice.oracle_exec_commandsql(s_pack_sql);
                            }
                        }
                        catch (Exception ec)
                        {
                            MessageBox.Show(ec.ToString());
                            return;
                        }
                    }
                    else
                    {
                        decimal i_ship_qty_m = Convert.ToDecimal(ds_count.Tables[0].Rows[0]["ship_qty_m"].ToString().Trim()) + 1;


                        try
                        {
                            if (main.dbtype == "SQL")
                            {
                                s_pack_sql = "update " + main.g_space + ".so_pack_detail set  main_dist ='C',update_time =getdate(),updater='" + main.g_username + "', ship_qty_m ='" + i_ship_qty_m + "' where inv_org ='" + main.g_org +
                                        "' and consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() +
                                        "' and so_no ='" + i_so_no + "' and box_no ='" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() +
                                        "' and so_line_no ='" + i_so_line_no + "'";
                                main.dbservice.Sql_exec_commandsql(s_pack_sql);
                                if (i_in_header_sql != "")
                                    main.dbservice.Sql_exec_commandsql(i_in_header_sql);
                            }
                            else
                            {
                                s_pack_sql = "update " + main.g_space + ".so_pack_detail set  main_dist ='C',update_time =sysdate,updater='" + main.g_username + "', ship_qty_m ='" + i_ship_qty_m + "' where inv_org ='" + main.g_org +
                                        "' and consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() +
                                        "' and so_no ='" + i_so_no + "' and box_no ='" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() +
                                        "' and so_line_no ='" + i_so_line_no + "'";
                                main.dbservice.oracle_exec_commandsql(s_pack_sql);
                                if (i_in_header_sql != "")
                                    main.dbservice.oracle_exec_commandsql(i_in_header_sql);
                            }
                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save box", main.g_info_dataset) + "!" + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                    so_bind();
                    dgv_so_pack_header.Rows[i_rowIndex].Selected = true;
                    //dgv_so_pack_header.CurrentCell = dgv_so_pack_header.Rows[i_rowIndex].Cells[1];
                    //dgv_so_pack_header_CurrentCellChanged(sender, e);
                    txt_add_sku.SelectAll();
                }

            }
            //}
            #endregion
            //如果是波次拣货
            #region 波次拣货
            //else
            //{
            //    if (dgv_so_ship_detail.Rows.Count > 0)
            //    {

            //        if (e.KeyChar == 13)
            //        {
            //            int i_rowIndex = dgv_so_pack_header.CurrentRow.Index;
            //            for (int k = 0; k < dgv_so_ship_detail.Rows.Count; k++)
            //            {
            //                if ((txt_add_sku.Text.ToString().Trim() == dgv_so_ship_detail.Rows[k].Cells["sku"].Value.ToString().Trim()) && (dgv_so_ship_detail.Rows[k].Cells["so_ship_consignor"].Value.ToString().Trim() == dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim()))
            //                {
            //                    i_same_count++;
            //                }
            //                if (dgv_so_ship_detail.Rows[k].Cells["check_uc"].Value.ToString().Trim() == "1")
            //                {
            //                    i_check_count++;
            //                }
            //                if ((txt_add_sku.Text.ToString().Trim() == dgv_so_ship_detail.Rows[k].Cells["sku"].Value.ToString().Trim()) && (dgv_so_ship_detail.Rows[k].Cells["so_ship_consignor"].Value.ToString().Trim() == dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim()))
            //                {
            //                    i_sku_count++;
            //                }
            //                //if (dgv_so_ship_detail.Rows[k].Cells["so_ship_consignor"].Value.ToString().Trim() == dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim())
            //                //{
            //                //    i_count++;
            //                //}                          
            //            }
            //            if ((i_same_count > 1) || (i_check_count == 0 && i_sku_count > 1))
            //            {
            //                MessageBox.Show("请选择要装箱的制定出库单商品");
            //                return;
            //            }
            //            else if (i_same_count == 1)
            //            {
            //                for (int r = 0; r < dgv_so_ship_detail.Rows.Count; r++)
            //                {
            //                    if ((txt_add_sku.Text.ToString().Trim() == dgv_so_ship_detail.Rows[r].Cells["sku"].Value.ToString().Trim()) && (dgv_so_ship_detail.Rows[r].Cells["so_ship_consignor"].Value.ToString().Trim() == dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim()))
            //                    {
            //                        //confirm_qty_m = Convert.ToDecimal(ds_wave_s.Tables[0].Rows[r]["confirm_qty_m"].ToString().Trim());

            //                        unbox_qty = Convert.ToDecimal(dgv_so_ship_detail.Rows[r].Cells["unbox_qty"].Value.ToString().Trim());
            //                        //判断数量是否超
            //                        if (unbox_qty<1)
            //                        {
            //                            MessageBox.Show("装箱数量不能大于剩余数量");
            //                            return;
            //                        }
            //                        i_wave_no = dgv_so_ship_detail.Rows[r].Cells["wave_no_ship_detail"].Value.ToString().Trim();
            //                        i_sku = dgv_so_ship_detail.Rows[r].Cells["sku"].Value.ToString().Trim();
            //                        i_pack_code = dgv_so_ship_detail.Rows[r].Cells["pack_code"].Value.ToString().Trim();
            //                        i_pick_qty_s = dgv_so_ship_detail.Rows[r].Cells["pick_qty_s"].Value.ToString().Trim();
            //                        i_order_price = dgv_so_ship_detail.Rows[r].Cells["order_price"].Value.ToString().Trim();
            //                        i_order_unit = dgv_so_ship_detail.Rows[r].Cells["order_unit"].Value.ToString().Trim();
            //                        i_pick_cubage = dgv_so_ship_detail.Rows[r].Cells["pick_cubage"].Value.ToString().Trim();
            //                        i_pick_gross_weight = dgv_so_ship_detail.Rows[r].Cells["pick_gross_weight"].Value.ToString().Trim();
            //                        i_pick_net_weight = dgv_so_ship_detail.Rows[r].Cells["pick_net_weight"].Value.ToString().Trim();
            //                        i_main_sub_flag = dgv_so_ship_detail.Rows[r].Cells["main_sub_flag"].Value.ToString().Trim();
            //                        i_convert_modulus = dgv_so_ship_detail.Rows[r].Cells["convert_modulus"].Value.ToString().Trim();
            //                    }
            //                }

            //            }
            //            else if (i_check_count == 1)
            //            {
            //                for (int r = 0; r < dgv_so_ship_detail.Rows.Count; r++)
            //                {
            //                    if (dgv_so_ship_detail.Rows[r].Cells["check_uc"].Value.ToString().Trim() == "1")
            //                    {
            //                        confirm_qty_m = Convert.ToDecimal(ds_wave_s.Tables[0].Rows[r]["confirm_qty_m"].ToString().Trim());

            //                        unbox_qty = Convert.ToDecimal(ds_wave_s.Tables[0].Rows[r]["unbox_qty"].ToString().Trim());
            //                        //判断数量是否超
            //                        if (confirm_qty_m >= unbox_qty)
            //                        {
            //                            MessageBox.Show("装箱数量不能大于剩余数量");
            //                            return;
            //                        }
            //                        i_wave_no = dgv_so_ship_detail.Rows[r].Cells["wave_no_ship_detail"].Value.ToString().Trim();
            //                        i_sku = dgv_so_ship_detail.Rows[r].Cells["sku"].Value.ToString().Trim();
            //                        i_pack_code = dgv_so_ship_detail.Rows[r].Cells["pack_code"].Value.ToString().Trim();
            //                        i_pick_qty_s = dgv_so_ship_detail.Rows[r].Cells["pick_qty_s"].Value.ToString().Trim();
            //                        i_order_price = dgv_so_ship_detail.Rows[r].Cells["order_price"].Value.ToString().Trim();
            //                        i_order_unit = dgv_so_ship_detail.Rows[r].Cells["order_unit"].Value.ToString().Trim();
            //                        i_pick_cubage = dgv_so_ship_detail.Rows[r].Cells["pick_cubage"].Value.ToString().Trim();
            //                        i_pick_gross_weight = dgv_so_ship_detail.Rows[r].Cells["pick_gross_weight"].Value.ToString().Trim();
            //                        i_pick_net_weight = dgv_so_ship_detail.Rows[r].Cells["pick_net_weight"].Value.ToString().Trim();
            //                        i_main_sub_flag = dgv_so_ship_detail.Rows[r].Cells["main_sub_flag"].Value.ToString().Trim();
            //                        i_convert_modulus = dgv_so_ship_detail.Rows[r].Cells["convert_modulus"].Value.ToString().Trim();
            //                    }
            //                }
            //            }
            //            else if (i_check_count == 0 && i_sku_count == 1)
            //            {
            //                for (int r = 0; r < dgv_so_ship_detail.Rows.Count; r++)
            //                {
            //                    if ((txt_add_sku.Text.ToString().Trim() == dgv_so_ship_detail.Rows[r].Cells["sku"].Value.ToString().Trim()) && (dgv_so_ship_detail.Rows[r].Cells["so_ship_consignor"].Value.ToString().Trim() == dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim()))
            //                    {
            //                        confirm_qty_m = Convert.ToDecimal(ds_wave_s.Tables[0].Rows[r]["confirm_qty_m"].ToString().Trim());

            //                        unbox_qty = Convert.ToDecimal(ds_wave_s.Tables[0].Rows[r]["unbox_qty"].ToString().Trim());
            //                        //判断数量是否超
            //                        if (confirm_qty_m >= unbox_qty)
            //                        {
            //                            MessageBox.Show("装箱数量不能大于剩余数量");
            //                            return;
            //                        }
            //                        i_wave_no = dgv_so_ship_detail.Rows[r].Cells["wave_no_ship_detail"].Value.ToString().Trim();
            //                        i_sku = dgv_so_ship_detail.Rows[r].Cells["sku"].Value.ToString().Trim();
            //                        i_pack_code = dgv_so_ship_detail.Rows[r].Cells["pack_code"].Value.ToString().Trim();
            //                        i_pick_qty_s = dgv_so_ship_detail.Rows[r].Cells["pick_qty_s"].Value.ToString().Trim();
            //                        i_order_price = dgv_so_ship_detail.Rows[r].Cells["order_price"].Value.ToString().Trim();
            //                        i_order_unit = dgv_so_ship_detail.Rows[r].Cells["order_unit"].Value.ToString().Trim();
            //                        i_pick_cubage = dgv_so_ship_detail.Rows[r].Cells["pick_cubage"].Value.ToString().Trim();
            //                        i_pick_gross_weight = dgv_so_ship_detail.Rows[r].Cells["pick_gross_weight"].Value.ToString().Trim();
            //                        i_pick_net_weight = dgv_so_ship_detail.Rows[r].Cells["pick_net_weight"].Value.ToString().Trim();
            //                        i_main_sub_flag = dgv_so_ship_detail.Rows[r].Cells["main_sub_flag"].Value.ToString().Trim();
            //                        i_convert_modulus = dgv_so_ship_detail.Rows[r].Cells["convert_modulus"].Value.ToString().Trim();
            //                    }
            //                }
            //            }
            //            else
            //            {
            //                MessageBox.Show("此箱子已被其他货主占用");
            //                return;
            //            }
            //            //判断有箱子
            //            if (dgv_so_pack_header.Rows.Count <= 0)
            //            {
            //                MessageBox.Show("请先增加一个箱子");
            //                return;
            //            }
            //            string str_sql = "select * from " + main.g_space + ".so_pack_detail where inv_org ='" + main.g_org + "' and " +
            //                            "consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "' and " +
            //                            "so_no = '" + i_wave_no + "' and box_no = '" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'and " +
            //                            "so_line_no ='1' and sku ='" + this.txt_add_sku.Text.ToString().Trim() + "'";
            //            string str_sql_pack_header = "select * from " + main.g_space + ".so_pack_header where status ='0' and inv_org ='" + main.g_org + "' and " +
            //                            "consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "' and " +
            //                            "so_no = '" + i_wave_no + "' and box_no = '" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'";
            //            if (main.dbtype == "SQL")
            //            {
            //                ds_count = main.dbservice.Sql_exec_selectsql(str_sql);
            //                ds_header_count = main.dbservice.Sql_exec_selectsql(str_sql_pack_header);
            //            }
            //            else
            //            {
            //                ds_count = main.dbservice.oracle_exec_selectsql(str_sql);
            //                ds_header_count = main.dbservice.Sql_exec_selectsql(str_sql_pack_header);
            //            }
            //            if (ds_header_count.Tables[0].Rows.Count == 0)
            //            {
            //                string i_net_werght;
            //                if (dgv_so_pack_header.CurrentRow.Cells["net_weight_so_pack_header"].Value.ToString().Trim() == "")
            //                {
            //                    i_net_werght = "null";
            //                }
            //                else
            //                {
            //                    i_net_werght = dgv_so_pack_header.CurrentRow.Cells["net_weight_so_pack_header"].Value.ToString().Trim();
            //                }
            //                if (main.dbtype == "SQL")
            //                {
            //                    i_in_header_sql = "insert into " + main.g_space + ".so_pack_header (inv_org,consignor,so_no,box_no,spec,box_size,net_weight,send_no,status,memo,main_dist,made_time,maker) values ( '" +
            //                            main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "','" +
            //                            i_wave_no + "','" +
            //                            dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "','" +
            //                            dgv_so_pack_header.CurrentRow.Cells["spec_so_pack_header"].Value.ToString().Trim() + "','" +
            //                            dgv_so_pack_header.CurrentRow.Cells["box_size_so_pack_header"].Value.ToString().Trim() + "'," +
            //                            i_net_werght + ",'" +
            //                            dgv_so_pack_header.CurrentRow.Cells["send_no_so_pack_header"].Value.ToString().Trim() + "','0','','A',getdate(),'" + main.g_username + "')";
            //                }
            //                else
            //                {
            //                    i_in_header_sql = "insert into " + main.g_space + ".so_pack_header (inv_org,consignor,so_no,box_no,spec,box_size,net_weight,send_no,status,memo,main_dist,made_time,maker) values ( '" +
            //                                main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "','" +
            //                                i_wave_no + "','" +
            //                                dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "','" +
            //                                dgv_so_pack_header.CurrentRow.Cells["spec_so_pack_header"].Value.ToString().Trim() + "','" +
            //                                dgv_so_pack_header.CurrentRow.Cells["box_size_so_pack_header"].Value.ToString().Trim() + "'," +
            //                                i_net_werght + ",'" +
            //                                dgv_so_pack_header.CurrentRow.Cells["send_no_so_pack_header"].Value.ToString().Trim() + "','0','','A',sysdate,'" + main.g_username + "')";
            //                }
            //            }
            //            if (ds_count.Tables[0].Rows.Count == 0)
            //            {
            //                try
            //                {
            //                    if (main.dbtype == "SQL")
            //                    {
            //                        s_pack_sql = "insert into " + main.g_space + ".so_pack_detail(inv_org,consignor,so_no,box_no,so_line_no,sku,ship_qty_m,pack_code,ship_qty_s,order_price,order_unit,ship_cubage,ship_gross_weight,ship_net_weight,main_sub_flag,convert_modulus,main_dist,made_time,maker) " +
            //                                   "values('" + main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "'," +
            //                                   "'" + i_wave_no + "'," +
            //                                   "'" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'," +
            //                                   "'1'," +
            //                                   "'" + i_sku + "'," +
            //                                   "'1'," +
            //                                   "'" + i_pack_code + "'," +
            //                                   "'" + i_pick_qty_s + "'," +
            //                                   "'" + i_order_price + "'," +
            //                                   "'" + i_order_unit + "'," +
            //                                   "'" + i_pick_cubage + "'," +
            //                                   "'" + i_pick_gross_weight + "'," +
            //                                   "'" + i_pick_net_weight + "'," +
            //                                   "'" + i_main_sub_flag + "'," +
            //                                   "'" + i_convert_modulus +
            //                                   "','A',getdate(),'" + main.g_username + "')";
            //                        main.dbservice.Sql_exec_commandsql(s_pack_sql);
            //                    }
            //                    else
            //                    {
            //                        s_pack_sql = "insert into " + main.g_space + ".so_pack_detail(inv_org,consignor,so_no,box_no,so_line_no,sku,ship_qty_m,pack_code,ship_qty_s,order_price,order_unit,ship_cubage,ship_gross_weight,ship_net_weight,main_sub_flag,convert_modulus,main_dist,made_time,maker) " +
            //                                   "values('" + main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "'," +
            //                                   "'" + i_wave_no + "'," +
            //                                   "'" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'," +
            //                                   "'1'," +
            //                                   "'" + i_sku + "'," +
            //                                   "'1'," +
            //                                   "'" + i_pack_code + "'," +
            //                                   "'" + i_pick_qty_s + "'," +
            //                                   "'" + i_order_price + "'," +
            //                                   "'" + i_order_unit + "'," +
            //                                   "'" + i_pick_cubage + "'," +
            //                                   "'" + i_pick_gross_weight + "'," +
            //                                   "'" + i_pick_net_weight + "'," +
            //                                   "'" + i_main_sub_flag + "'," +
            //                                   "'" + i_convert_modulus +
            //                                   "','A',sysdate,'" + main.g_username + "')";
            //                        main.dbservice.oracle_exec_commandsql(s_pack_sql);
            //                    }
            //                }
            //                catch (Exception ec)
            //                {
            //                    MessageBox.Show(ec.ToString());
            //                    return;
            //                }
            //            }
            //            else
            //            {
            //                decimal i_ship_qty_m = Convert.ToDecimal(ds_count.Tables[0].Rows[0]["ship_qty_m"].ToString().Trim()) + 1;


            //                try
            //                {
            //                    if (main.dbtype == "SQL")
            //                    {
            //                        s_pack_sql = "update " + main.g_space + ".so_pack_detail set  main_dist ='C',update_time =getdate(),updater='" + main.g_username + "', ship_qty_m ='" + i_ship_qty_m + "' where inv_org ='" + main.g_org +
            //                                "' and consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() +
            //                                "' and so_no ='" + i_wave_no + "' and box_no ='" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() +
            //                                "' and sku = '" + this.txt_add_sku.Text.ToString().Trim() + "'";
            //                        main.dbservice.Sql_exec_commandsql(s_pack_sql);
            //                        if (i_in_header_sql != "")
            //                            main.dbservice.Sql_exec_commandsql(i_in_header_sql);
            //                    }
            //                    else
            //                    {
            //                        s_pack_sql = "update " + main.g_space + ".so_pack_detail set  main_dist ='C',update_time =sysdate,updater='" + main.g_username + "', ship_qty_m ='" + i_ship_qty_m + "' where inv_org ='" + main.g_org +
            //                                "' and consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() +
            //                                "' and so_no ='" + i_wave_no + "' and box_no ='" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() +
            //                                "' and sku ='" + this.txt_add_sku.Text.ToString().Trim() + "' ";
            //                        main.dbservice.oracle_exec_commandsql(s_pack_sql);
            //                        if (i_in_header_sql != "")
            //                            main.dbservice.oracle_exec_commandsql(i_in_header_sql);
            //                    }
            //                }
            //                catch (System.Exception ee)
            //                {
            //                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to save box", main.g_info_dataset) + "!" + ee.ToString());
            //                    Cursor.Current = Cursors.Default;
            //                    return;
            //                }
            //            }
            //            so_bind();
            //            dgv_so_pack_header.Rows[i_rowIndex].Selected = true;
            //            dgv_so_pack_header.CurrentCell = dgv_so_pack_header.Rows[i_rowIndex].Cells[1];
            //            dgv_so_pack_header_CurrentCellChanged(sender, e);
            //            txt_add_sku.SelectAll();
            //        }

            //    }
            //}
            #endregion

        }

        private void btn_load_Click(object sender, EventArgs e)
        {
            if (this.dgv_so_pack_header.Rows.Count < 1)
            {
                MessageBox.Show("请新增一个箱子!");
                return;
            }
            #region 一单拣货
            //if (this.cmb_type.SelectedIndex == 0)
            //{
            DataSet ds_count = new DataSet();
            DataSet ds_select_count = new DataSet();
            for (int i = 0; i < dgv_so_ship_detail.Rows.Count; i++)
            {
                if (dgv_so_ship_detail.Rows[i].Cells["check_uc"].Value.ToString().Trim() == "True")
                {
                    for (int j = 0; j < dgv_so_ship_detail.Rows.Count; j++)
                    {
                        if (dgv_so_ship_detail.Rows[j].Cells["check_uc"].Value.ToString().Trim() == "True")
                        {
                            if ((dgv_so_ship_detail.Rows[i].Cells["so_ship_consignor"].Value.ToString().Trim() != dgv_so_ship_detail.Rows[j].Cells["so_ship_consignor"].Value.ToString().Trim()) && (i != j))
                            {
                                MessageBox.Show("请选择相同货主的物料!");
                                return;
                            }
                        }
                    }
                }
            }
            int count = 0;
            for (int i = 0; i < dgv_so_ship_detail.Rows.Count; i++)
            {
                if ((dgv_so_ship_detail.Rows[i].Cells["check_uc"].Value.ToString().Trim() == "True") && (dgv_so_ship_detail.Rows[i].Cells["so_ship_consignor"].Value.ToString().Trim() != dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim()))
                {
                    count++;
                }
            }
            if (count > 0)
            {
                MessageBox.Show("此箱子已被其他货主占用!");
                return;
            }
            int check_pack_header = 0;
            for (int i = 0; i < dgv_so_ship_detail.Rows.Count; i++)
            {
                if (dgv_so_ship_detail.Rows[i].Cells["check_uc"].Value.ToString().Trim() == "True")
                {
                    if (Convert.ToDouble(dgv_so_ship_detail.Rows[i].Cells["unbox_qty"].Value.ToString().Trim()) < Convert.ToDouble(dgv_so_ship_detail.Rows[i].Cells["confirm_qty_m"].Value.ToString().Trim()))
                    {
                        MessageBox.Show("装箱数量不能大于剩余数量!");
                        return;
                    }
                    string str_sql = "select * from " + main.g_space + ".so_pack_detail where inv_org ='" + main.g_org + "' and " +
                                        "consignor ='" + dgv_so_ship_detail.Rows[i].Cells["so_ship_consignor"].Value.ToString().Trim() + "' and " +
                                        "so_no = '" + dgv_so_ship_detail.Rows[i].Cells["so_no_ship_detail"].Value.ToString().Trim() + "' and box_no = '" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'and " +
                                        "so_line_no ='" + dgv_so_ship_detail.Rows[i].Cells["so_line_no"].Value.ToString().Trim() + "'";
                    string str_select_header_sql = "select * from " + main.g_space + ".so_pack_header where status='0' and inv_org ='" + main.g_org + "' and " +
                                        "consignor ='" + dgv_so_ship_detail.Rows[i].Cells["so_ship_consignor"].Value.ToString().Trim() + "' and " +
                                        "so_no = '" + dgv_so_ship_detail.Rows[i].Cells["so_no_ship_detail"].Value.ToString().Trim() + "' and box_no = '" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'";
                    try
                    {
                        if (main.dbtype == "SQL")
                        {
                            ds_count = main.dbservice.Sql_exec_selectsql(str_sql);
                            ds_select_count = main.dbservice.Sql_exec_selectsql(str_select_header_sql);
                        }
                        else
                        {
                            ds_count = main.dbservice.oracle_exec_selectsql(str_sql);
                            ds_select_count = main.dbservice.oracle_exec_selectsql(str_select_header_sql);
                        }
                    }
                    catch (Exception ee)
                    {
                        MessageBox.Show(ee.ToString());
                        return;
                    }
                    string i_in_header_sql = "";
                    //string i_up_header_sql = "";
                    if (ds_select_count.Tables[0].Rows.Count == 0)
                    {
                        string i_net_werght;
                        if (dgv_so_pack_header.CurrentRow.Cells["net_weight_so_pack_header"].Value.ToString().Trim() == "")
                        {
                            i_net_werght = "null";
                        }
                        else
                        {
                            i_net_werght = dgv_so_pack_header.CurrentRow.Cells["net_weight_so_pack_header"].Value.ToString().Trim();
                        }
                        if (main.dbtype == "SQL")
                        {
                            string i_send_type;
                            if (dgv_so_pack_header.CurrentRow.Cells["send_type_so_pack_header"].Value.ToString().Trim() == "")
                                i_send_type = "NULL";
                            else
                                i_send_type = "'" + dgv_so_pack_header.CurrentRow.Cells["send_type_so_pack_header"].Value.ToString().Trim() + "'";
                            //i_in_header_sql = "insert into " + main.g_space + ".so_pack_header (inv_org,consignor,so_no,box_no,spec,box_size,net_weight,send_no,status,memo,main_dist,made_time,maker) values ( '" +
                            //        main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "','" +
                            //        dgv_so_ship_detail.Rows[i].Cells["so_no_ship_detail"].Value.ToString().Trim() + "','" +
                            //        dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "','" +
                            //        dgv_so_pack_header.CurrentRow.Cells["spec_so_pack_header"].Value.ToString().Trim() + "','" +
                            //        dgv_so_pack_header.CurrentRow.Cells["box_size_so_pack_header"].Value.ToString().Trim() + "'," +
                            //        i_net_werght + ",'" +
                            //        dgv_so_pack_header.CurrentRow.Cells["send_no_so_pack_header"].Value.ToString().Trim() + "','0','','A',getdate(),'" + main.g_username + "')";
                            //i_up_header_sql = "update " + main.g_space + ".so_pack_header set address ='" + dgv_so_pack_header.CurrentRow.Cells["address_so_pack_header"].Value.ToString().Trim() + "', send_type=" + i_send_type + ", main_dist ='C',update_time =getdate(),updater='" + main.g_username + "', net_weight =" + i_net_werght +
                            //                " where status='0' and inv_org ='" + dgv_so_pack_header.CurrentRow.Cells["inv_org_so_pack_header"].Value.ToString().Trim() +
                            //                "' and consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() +
                            //                "' and box_no ='" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'";
                            i_in_header_sql = "insert into wms.so_pack_header ([inv_org],[consignor],[so_no],[box_no],[spec],[box_size],[net_weight],[send_no],[carrier],[carrier_address],[carrier_postalcode],[carrier_phone],[ship_no],[fly_no],[vehicle_no],[standby_1],[standby_2],[standby_3],[standby_4],[standby_5],[standby_6],[standby_7],[memo],[main_dist],[made_time],[maker],[status]" +
                                            ",[ship_day],[shipper],[address],[send_type])  select top 1 [inv_org],[consignor],'" + dgv_so_ship_detail.Rows[i].Cells["so_no_ship_detail"].Value.ToString().Trim() + "',[box_no],[spec],[box_size],[net_weight],[send_no],[carrier],[carrier_address],[carrier_postalcode],[carrier_phone],[ship_no],[fly_no],[vehicle_no],[standby_1],[standby_2],[standby_3],[standby_4],[standby_5],[standby_6],[standby_7],[memo],'A',getdate(),'" + main.g_user + "',[status]" +
                                            ",[ship_day],[shipper],[address],[send_type] from wms.so_pack_header where inv_org = '" + main.g_org + "' and consignor = '" + dgv_so_ship_header.CurrentRow.Cells["consignor"].Value.ToString().Trim() + "' and box_no ='" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'";
                            main.dbservice.Sql_exec_commandsql(str_sql);
                        }
                        else
                        {
                            i_in_header_sql = "insert into " + main.g_space + ".so_pack_header (inv_org,consignor,so_no,box_no,spec,box_size,net_weight,send_no,status,memo,main_dist,made_time,maker) values ( '" +
                                        main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "','" +
                                        dgv_so_ship_detail.Rows[i].Cells["so_no_ship_detail"].Value.ToString().Trim() + "','" +
                                        dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "','" +
                                        dgv_so_pack_header.CurrentRow.Cells["spec_so_pack_header"].Value.ToString().Trim() + "','" +
                                        dgv_so_pack_header.CurrentRow.Cells["box_size_so_pack_header"].Value.ToString().Trim() + "'," +
                                        i_net_werght + ",'" +
                                        dgv_so_pack_header.CurrentRow.Cells["send_no_so_pack_header"].Value.ToString().Trim() + "','0','','A',sysdate,'" + main.g_username + "')";
                        }
                        try
                        {
                            if (main.dbtype == "SQL")
                            {
                                main.dbservice.Sql_exec_commandsql(i_in_header_sql);
                                //main.dbservice.Sql_exec_commandsql(i_up_header_sql);
                            }
                            else
                            {
                                main.dbservice.oracle_exec_commandsql(i_in_header_sql);
                            }
                        }
                        catch (Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save box", main.g_info_dataset) + "!" + ee.ToString());
                            return;
                        }
                    }
                    try
                    {
                        DataSet ds_gross;
                        string str_sql2 = "select isnull(sum(a.ship_qty_m*b.gross_weight),0) gross_weight from " + main.g_space + ".so_pack_detail a,wms.mst_sku b where a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku and a.inv_org ='" + main.g_org + "' and " +
                                        " a.consignor ='" + dgv_so_ship_detail.Rows[i].Cells["so_ship_consignor"].Value.ToString().Trim() + "'  " +
                                        " and box_no = '" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "' ";

                        ds_gross = main.dbservice.Sql_exec_selectsql(str_sql2);

                        decimal d_gross_weight_sum = 0, d_box_weight = 0, d_old_gross = 0;
                        if (ds_gross.Tables[0].Rows.Count > 0)
                        {
                            d_old_gross = Convert.ToDecimal(ds_gross.Tables[0].Rows[0]["gross_weight"].ToString().Trim());
                        }
                        else
                        {
                            d_old_gross = 0;
                        }
                        d_box_weight = Convert.ToDecimal(dgv_so_pack_header.CurrentRow.Cells["net_weight_so_pack_header"].Value.ToString().Trim());
                        d_gross_weight_sum = Math.Round(Convert.ToDecimal(dgv_so_ship_detail.Rows[i].Cells["confirm_qty_m"].Value.ToString().Trim()) * Convert.ToDecimal(dgv_so_ship_detail.Rows[i].Cells["gross_weight"].Value.ToString().Trim()), 4);
                        d_gross_weight_sum = d_gross_weight_sum + d_old_gross;
                        if (d_gross_weight_sum > d_box_weight)
                        {
                            MessageBox.Show("装箱净重大于箱子毛重");
                           
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show("计算净重是否大于毛重失败"+ee.Message);
                    }
                    if (ds_count.Tables[0].Rows.Count > 0)
                    {
                       

                        double s_ship_qty_m = Convert.ToDouble(ds_count.Tables[0].Rows[0]["ship_qty_m"].ToString().Trim()) + Convert.ToDouble(dgv_so_ship_detail.Rows[i].Cells["confirm_qty_m"].Value.ToString().Trim());

                        try
                        {
                            if (main.dbtype == "SQL")
                            {
                                string update_sql = "update " + main.g_space + ".so_pack_detail set main_dist ='C',update_time =getdate(),updater='" + main.g_username + "', ship_qty_m ='" + s_ship_qty_m.ToString() + "' where inv_org ='" + main.g_org + "' and consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "'" +
                                " and so_no ='" + dgv_so_ship_detail.Rows[i].Cells["so_no_ship_detail"].Value.ToString().Trim() + "'" +
                                " and box_no = '" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'" +
                                "and so_line_no ='" + dgv_so_ship_detail.Rows[i].Cells["so_line_no"].Value.ToString().Trim() + "'";
                                main.dbservice.Sql_exec_commandsql(update_sql);
                            }
                            else
                            {
                                string update_sql = "update " + main.g_space + ".so_pack_detail set main_dist ='C',update_time =sysdate,updater='" + main.g_username + "', ship_qty_m ='" + s_ship_qty_m.ToString() + "' where inv_org ='" + main.g_org + "' and consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "'" +
                                " and so_no ='" + dgv_so_ship_detail.Rows[i].Cells["so_no_ship_detail"].Value.ToString().Trim() + "'" +
                                " and box_no = '" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'" +
                                "and so_line_no ='" + dgv_so_ship_detail.Rows[i].Cells["so_line_no"].Value.ToString().Trim() + "'";
                                main.dbservice.oracle_exec_commandsql(update_sql);
                            }
                        }
                        catch (Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save box", main.g_info_dataset) + "!" + ee.ToString());
                            return;
                        }

                    }
                    else
                    {
                       

                        //decimal d_gross_weight_sum = 0, d_box_weight = 0;

                        //d_box_weight = Convert.ToDecimal(dgv_so_pack_header.CurrentRow.Cells["net_weight_so_pack_header"].Value.ToString().Trim());
                        //d_gross_weight_sum = Math.Round(Convert.ToDecimal(dgv_so_ship_detail.Rows[i].Cells["confirm_qty_m"].Value.ToString().Trim()) * Convert.ToDecimal(dgv_so_ship_detail.Rows[i].Cells["gross_weight"].Value.ToString().Trim()), 4);
                        //if (d_gross_weight_sum > d_box_weight)
                        //{
                        //    MessageBox.Show("装箱净重大于箱子毛重.");
                        //    so_bind();
                        //    return;
                        //}
                        if (dgv_so_ship_detail.Rows[i].Cells["unbox_qty"].Value.ToString().Trim() != "0.0000")
                        {
                            string insert_sql = "";
                            if (main.dbtype == "SQL")
                            {
                                insert_sql = "insert into " + main.g_space + ".so_pack_detail(inv_org,consignor,so_no,box_no,so_line_no,sku,ship_qty_m,pack_code,ship_qty_s,order_price,order_unit,ship_cubage,ship_gross_weight,ship_net_weight,main_sub_flag,convert_modulus,main_dist,made_time,maker) " +
                                               "values('" + main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["so_no_ship_detail"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["so_line_no"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["sku"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["confirm_qty_m"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["pack_code"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["pick_qty_s"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["order_price"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["order_unit"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["pick_cubage"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["pick_gross_weight"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["pick_net_weight"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["main_sub_flag"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["convert_modulus"].Value.ToString().Trim() +
                                               "','A',getdate(),'" + main.g_username + "')";
                            }
                            else
                            {
                                insert_sql = "insert into " + main.g_space + ".so_pack_detail(inv_org,consignor,so_no,box_no,so_line_no,sku,ship_qty_m,pack_code,ship_qty_s,order_price,order_unit,ship_cubage,ship_gross_weight,ship_net_weight,main_sub_flag,convert_modulus,main_dist,made_time,maker) " +
                                               "values('" + main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["so_no_ship_detail"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["so_line_no"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["sku"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["confirm_qty_m"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["pack_code"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["pick_qty_s"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["order_price"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["order_unit"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["pick_cubage"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["pick_gross_weight"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["pick_net_weight"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["main_sub_flag"].Value.ToString().Trim() + "'," +
                                               "'" + dgv_so_ship_detail.Rows[i].Cells["convert_modulus"].Value.ToString().Trim() +
                                               "','A',sysdate,'" + main.g_username + "')";
                            }

                            try
                            {
                                if (main.dbtype == "SQL")
                                {
                                    main.dbservice.Sql_exec_commandsql(insert_sql);
                                }
                                else
                                {
                                    main.dbservice.oracle_exec_commandsql(insert_sql);
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(main.g_class.comm_getchangestring("Fail to save box", main.g_info_dataset) + "!" + ex.ToString());
                                return;
                            }
                        }

                    }
                    check_pack_header++;
                }

            }
            if (check_pack_header == 0)
            {
                MessageBox.Show("请选择要装箱的物料!");
                return;
            }
            //}
            #endregion
            #region 如果是波次拣货
            //else
            //{
            //    DataSet ds_count = new DataSet();
            //    DataSet ds_select_count = new DataSet();
            //    for (int i = 0; i < dgv_so_ship_detail.Rows.Count; i++)
            //    {
            //        if (dgv_so_ship_detail.Rows[i].Cells["check_uc"].Value.ToString().Trim() == "1")
            //        {
            //            for (int j = 0; j < dgv_so_ship_detail.Rows.Count; j++)
            //            {
            //                if (dgv_so_ship_detail.Rows[j].Cells["check_uc"].Value.ToString().Trim() == "1")
            //                {
            //                    if ((dgv_so_ship_detail.Rows[i].Cells["so_ship_consignor"].Value.ToString().Trim() != dgv_so_ship_detail.Rows[j].Cells["so_ship_consignor"].Value.ToString().Trim()) && (i != j))
            //                    {
            //                        MessageBox.Show("请选择相同货主的物料!");
            //                        return;
            //                    }
            //                }
            //            }
            //        }
            //    }
            //    int count = 0;
            //    for (int i = 0; i < dgv_so_ship_detail.Rows.Count; i++)
            //    {
            //        if ((dgv_so_ship_detail.Rows[i].Cells["check_uc"].Value.ToString().Trim() == "1") && (dgv_so_ship_detail.Rows[i].Cells["so_ship_consignor"].Value.ToString().Trim() != dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim()))
            //        {
            //            count++;
            //        }
            //    }
            //    if (count > 0)
            //    {
            //        MessageBox.Show("此箱子已被其他货主占用!");
            //        return;
            //    }
            //    int check_pack_header = 0;
            //    for (int i = 0; i < dgv_so_ship_detail.Rows.Count; i++)
            //    {
            //        if (dgv_so_ship_detail.Rows[i].Cells["check_uc"].Value.ToString().Trim() == "1")
            //        {
            //            if (Convert.ToDouble(dgv_so_ship_detail.Rows[i].Cells["unbox_qty"].Value.ToString().Trim()) < Convert.ToDouble(dgv_so_ship_detail.Rows[i].Cells["confirm_qty_m"].Value.ToString().Trim()))
            //            {
            //                MessageBox.Show("装箱数量不能大于剩余数量!");
            //                return;
            //            }
            //            string str_sql = "select * from " + main.g_space + ".so_pack_detail where inv_org ='" + main.g_org + "' and " +
            //                                "consignor ='" + dgv_so_ship_detail.Rows[i].Cells["so_ship_consignor"].Value.ToString().Trim() + "' and " +
            //                                "so_no = '" + dgv_so_ship_detail.Rows[i].Cells["wave_no_ship_detail"].Value.ToString().Trim() + "' and box_no = '" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'and " +
            //                                "so_line_no ='1' and sku ='" + dgv_so_ship_detail.Rows[i].Cells["sku"].Value.ToString().Trim() + "'";
            //            string str_select_header_sql = "select * from " + main.g_space + ".so_pack_header where status='0' and inv_org ='" + main.g_org + "' and " +
            //                                "consignor ='" + dgv_so_ship_detail.Rows[i].Cells["so_ship_consignor"].Value.ToString().Trim() + "' and " +
            //                                "so_no = '" + dgv_so_ship_detail.Rows[i].Cells["wave_no_ship_detail"].Value.ToString().Trim() + "' and box_no = '" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'";
            //            try
            //            {
            //                if (main.dbtype == "SQL")
            //                {
            //                    ds_count = main.dbservice.Sql_exec_selectsql(str_sql);
            //                    ds_select_count = main.dbservice.Sql_exec_selectsql(str_select_header_sql);
            //                }
            //                else
            //                {
            //                    ds_count = main.dbservice.oracle_exec_selectsql(str_sql);
            //                    ds_select_count = main.dbservice.oracle_exec_selectsql(str_select_header_sql);
            //                }
            //            }
            //            catch (Exception ee)
            //            {
            //                MessageBox.Show(ee.ToString());
            //                return;
            //            }
            //            string i_in_header_sql = "";
            //            if (ds_select_count.Tables[0].Rows.Count == 0)
            //            {
            //                string i_net_werght;
            //                if (dgv_so_pack_header.CurrentRow.Cells["net_weight_so_pack_header"].Value.ToString().Trim() == "")
            //                {
            //                    i_net_werght = "null";
            //                }
            //                else
            //                {
            //                    i_net_werght = dgv_so_pack_header.CurrentRow.Cells["net_weight_so_pack_header"].Value.ToString().Trim();
            //                }
            //                if (main.dbtype == "SQL")
            //                {
            //                    i_in_header_sql = "insert into " + main.g_space + ".so_pack_header (inv_org,consignor,so_no,box_no,spec,box_size,net_weight,send_no,status,memo,main_dist,made_time,maker) values ( '" +
            //                            main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "','" +
            //                            dgv_so_ship_detail.Rows[i].Cells["wave_no_ship_detail"].Value.ToString().Trim() + "','" +
            //                            dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "','" +
            //                            dgv_so_pack_header.CurrentRow.Cells["spec_so_pack_header"].Value.ToString().Trim() + "','" +
            //                            dgv_so_pack_header.CurrentRow.Cells["box_size_so_pack_header"].Value.ToString().Trim() + "'," +
            //                            i_net_werght + ",'" +
            //                            dgv_so_pack_header.CurrentRow.Cells["send_no_so_pack_header"].Value.ToString().Trim() + "','0','','A',getdate(),'" + main.g_username + "')";
            //                }
            //                else
            //                {
            //                    i_in_header_sql = "insert into " + main.g_space + ".so_pack_header (inv_org,consignor,so_no,box_no,spec,box_size,net_weight,send_no,status,memo,main_dist,made_time,maker) values ( '" +
            //                                main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "','" +
            //                                dgv_so_ship_detail.Rows[i].Cells["wave_no_ship_detail"].Value.ToString().Trim() + "','" +
            //                                dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "','" +
            //                                dgv_so_pack_header.CurrentRow.Cells["spec_so_pack_header"].Value.ToString().Trim() + "','" +
            //                                dgv_so_pack_header.CurrentRow.Cells["box_size_so_pack_header"].Value.ToString().Trim() + "'," +
            //                                i_net_werght + ",'" +
            //                                dgv_so_pack_header.CurrentRow.Cells["send_no_so_pack_header"].Value.ToString().Trim() + "','0','','A',sysdate,'" + main.g_username + "')";
            //                }
            //                try
            //                {
            //                    if (main.dbtype == "SQL")
            //                    {
            //                        main.dbservice.Sql_exec_commandsql(i_in_header_sql);
            //                    }
            //                    else
            //                    {
            //                        main.dbservice.oracle_exec_commandsql(i_in_header_sql);
            //                    }
            //                }
            //                catch (Exception ee)
            //                {
            //                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to save box", main.g_info_dataset) + "!" + ee.ToString());
            //                    return;
            //                }
            //            }
            //            if (ds_count.Tables[0].Rows.Count > 0)
            //            {
            //                double s_ship_qty_m = Convert.ToDouble(ds_count.Tables[0].Rows[0]["ship_qty_m"].ToString().Trim()) + Convert.ToDouble(dgv_so_ship_detail.Rows[i].Cells["confirm_qty_m"].Value.ToString().Trim());

            //                try
            //                {
            //                    if (main.dbtype == "SQL")
            //                    {
            //                        string update_sql = "update " + main.g_space + ".so_pack_detail set main_dist ='C',update_time =getdate(),updater='" + main.g_username + "', ship_qty_m ='" + s_ship_qty_m.ToString() + "' where inv_org ='" + main.g_org + "' and consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "'" +
            //                        " and so_no ='" + dgv_so_ship_detail.Rows[i].Cells["wave_no_ship_detail"].Value.ToString().Trim() + "'" +
            //                        " and box_no = '" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'" +
            //                        "and so_line_no ='1' and sku ='" + dgv_so_ship_detail.Rows[i].Cells["sku"].Value.ToString().Trim() + "'";
            //                        main.dbservice.Sql_exec_commandsql(update_sql);
            //                    }
            //                    else
            //                    {
            //                        string update_sql = "update " + main.g_space + ".so_pack_detail set main_dist ='C',update_time =sysdate,updater='" + main.g_username + "', ship_qty_m ='" + s_ship_qty_m.ToString() + "' where inv_org ='" + main.g_org + "' and consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "'" +
            //                        " and so_no ='" + dgv_so_ship_detail.Rows[i].Cells["wave_no_ship_detail"].Value.ToString().Trim() + "'" +
            //                        " and box_no = '" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'" +
            //                        "and so_line_no ='1' and sku ='" + dgv_so_ship_detail.Rows[i].Cells["sku"].Value.ToString().Trim() + "'";
            //                        main.dbservice.oracle_exec_commandsql(update_sql);
            //                    }
            //                }
            //                catch (Exception ee)
            //                {
            //                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to save box", main.g_info_dataset) + "!" + ee.ToString());
            //                    return;
            //                }

            //            }
            //            else
            //            {
            //                if (dgv_so_ship_detail.Rows[i].Cells["unbox_qty"].Value.ToString().Trim() != "0.0000")
            //                {
            //                    string insert_sql = "";
            //                    if (main.dbtype == "SQL")
            //                    {
            //                        insert_sql = "insert into " + main.g_space + ".so_pack_detail(inv_org,consignor,so_no,box_no,so_line_no,sku,ship_qty_m,pack_code,ship_qty_s,order_price,order_unit,ship_cubage,ship_gross_weight,ship_net_weight,main_sub_flag,convert_modulus,main_dist,made_time,maker) " +
            //                                       "values('" + main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["wave_no_ship_detail"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'," +
            //                                       "'1'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["sku"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["confirm_qty_m"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["pack_code"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["pick_qty_s"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["order_price"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["order_unit"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["pick_cubage"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["pick_gross_weight"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["pick_net_weight"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["main_sub_flag"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["convert_modulus"].Value.ToString().Trim() +
            //                                       "','A',getdate(),'" + main.g_username + "')";
            //                    }
            //                    else
            //                    {
            //                        insert_sql = "insert into " + main.g_space + ".so_pack_detail(inv_org,consignor,so_no,box_no,so_line_no,sku,ship_qty_m,pack_code,ship_qty_s,order_price,order_unit,ship_cubage,ship_gross_weight,ship_net_weight,main_sub_flag,convert_modulus,main_dist,made_time,maker) " +
            //                                       "values('" + main.g_org + "','" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["wave_no_ship_detail"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'," +
            //                                       "'1'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["sku"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["confirm_qty_m"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["pack_code"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["pick_qty_s"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["order_price"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["order_unit"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["pick_cubage"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["pick_gross_weight"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["pick_net_weight"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["main_sub_flag"].Value.ToString().Trim() + "'," +
            //                                       "'" + dgv_so_ship_detail.Rows[i].Cells["convert_modulus"].Value.ToString().Trim() +
            //                                       "','A',sysdate,'" + main.g_username + "')";
            //                    }

            //                    try
            //                    {
            //                        if (main.dbtype == "SQL")
            //                        {
            //                            main.dbservice.Sql_exec_commandsql(insert_sql);
            //                        }
            //                        else
            //                        {
            //                            main.dbservice.oracle_exec_commandsql(insert_sql);
            //                        }
            //                    }
            //                    catch (Exception ex)
            //                    {
            //                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to save box", main.g_info_dataset) + "!" + ex.ToString());
            //                        return;
            //                    }
            //                }

            //            }
            //            check_pack_header++;
            //        }

            //    }
            //    if (check_pack_header == 0)
            //    {
            //        MessageBox.Show("请选择要装箱的物料!");
            //        return;
            //    }
            //}
            #endregion
            so_bind();

        }

        private void btn_unload_Click(object sender, EventArgs e)
        {
            DataSet ds_count = new DataSet();
            //有数据
            if (dgv_so_pack_header.CurrentRow != null)
            {
                string s_select_sql = "select * from " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' " +
                               " and consignor='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "' " +
                               "and box_no='" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "' and main_dist <> 'D' ";
                try
                {
                    if (main.dbtype == "SQL")
                    {
                        ds_count = main.dbservice.Sql_exec_selectsql(s_select_sql);
                    }
                    else
                    {
                        ds_count = main.dbservice.oracle_exec_selectsql(s_select_sql);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to delete box", main.g_info_dataset) + ex.ToString());
                    return;
                }
                if (ds_count.Tables[0].Rows.Count > 0)
                {
                    string s_sql = "delete " + main.g_space + ".so_pack_detail where inv_org='" + main.g_org + "' " +
                                   " and consignor='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "' " +
                                   "and box_no='" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'";

                    try
                    {
                        if (main.dbtype == "SQL")
                            main.dbservice.Sql_exec_commandsql(s_sql);
                        else
                            main.dbservice.oracle_exec_commandsql(s_sql);
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Failed! ", main.g_info_dataset) + ee.ToString());
                        return;
                    }
                    so_bind();
                }
                else
                {
                    MessageBox.Show("此箱子是空的!");
                    return;
                }
            }
        }

        private void dgv_so_ship_detail_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //如果点击的不是表头
            if (e.RowIndex >= 0)
            {
                //点击的是复选框
                if (e.ColumnIndex == 0)
                {
                    //改变CheckBox状态
                    if ((bool)dgv_so_ship_detail.CurrentRow.Cells["check_uc"].EditedFormattedValue)
                    {
                        dgv_so_ship_detail.CurrentRow.Cells["check_uc"].Value = "False";
                        dgv_so_ship_detail.CurrentRow.Cells["confirm_qty_m"].Value = "0";
                        ////将已扫的SKU取消
                        //DataTable dt = new DataTable();
                        //dgv_sku_add.DataSource = dt;
                    }
                    else
                    {
                        dgv_so_ship_detail.CurrentRow.Cells["check_uc"].Value = "True";
                        dgv_so_ship_detail.CurrentRow.Cells["confirm_qty_m"].Value = dgv_so_ship_detail.CurrentRow.Cells["unbox_qty"].Value;
                    }
                }
                if ((bool)dgv_so_ship_detail.CurrentRow.Cells["check_uc"].EditedFormattedValue)
                {
                    //如果点击的是确认数量列启动编辑
                    if (e.ColumnIndex == 9)
                    {
                        dgv_so_ship_detail.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
                    }
                    else
                    {
                        dgv_so_ship_detail.EditMode = DataGridViewEditMode.EditProgrammatically;
                    }
                }
                else
                {
                    dgv_so_ship_detail.EditMode = DataGridViewEditMode.EditProgrammatically;
                }
            }
        }

        private void dgv_so_pack_header_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //if (e.ColumnIndex == 4)
            //{
            //    _Rectangle = dgv_so_pack_header.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); //得到所在单元格位置和大小
            //    cmb_send_type.Size = new Size(_Rectangle.Width, _Rectangle.Height); //把单元格大小赋给时间控件

            //    cmb_send_type.Location = new Point(_Rectangle.X, _Rectangle.Y); //把单元格位置赋给时间控件

            //    cmb_send_type.Visible = true;  //可以显示控件了

            //    DataSet ds_temp_2 = new DataSet();
            //    ds_temp_2.Tables.Add("0");
            //    ds_temp_2.Tables[0].Columns.Add("send_type");
            //    ds_temp_2.Tables[0].Columns.Add("send_type_name");
            //    DataRow drnew;
            //    drnew = ds_temp_2.Tables[0].NewRow();
            //    drnew["send_type"] = "0";
            //    drnew["send_type_name"] = "包裹";
            //    ds_temp_2.Tables[0].Rows.Add(drnew);

            //    DataRow drnew2;
            //    drnew2 = ds_temp_2.Tables[0].NewRow();
            //    drnew2["send_type"] = "1";
            //    drnew2["send_type_name"] = "公路";
            //    ds_temp_2.Tables[0].Rows.Add(drnew2);
            //    cmb_send_type.ValueMember = "send_type";
            //    cmb_send_type.DisplayMember = "send_type_name";
            //    cmb_send_type.DataSource = ds_temp_2.Tables[0];
            //    cmb_send_type.SelectedItem = dgv_so_pack_header.CurrentRow.Cells["send_type_so_pack_header"].Value.ToString().Trim();
            //    if (dgv_so_pack_header.CurrentRow.Cells["send_type_so_pack_header"].Value.ToString().Trim() == "公路")
            //        cmb_send_type.SelectedIndex = 1;
            //    else
            //        cmb_send_type.SelectedIndex = 0;
            //}
            //else
            //{
            //    cmb_send_type.Visible = false;
            //}
        }

        private void cmb_send_type_Change(object sender, EventArgs e)
        {
            //dgv_so_pack_header.CurrentRow.Cells["send_type_so_pack_header"].Value = cmb_send_type.Text.ToString().Trim();  //时间控件选择时间时，就把时间赋给所在的单元格

            //if (ds_address.Tables[0].Rows.Count > 0)
            //{
            //    if (dgv_so_pack_header.CurrentRow.Cells["send_type_so_pack_header"].Value.ToString().Trim() == "包裹")
            //    {
            //        dgv_so_pack_header.CurrentRow.Cells["standby"].Value = ds_address.Tables[0].Rows[0]["standby_11"].ToString().Trim();
            //    }
            //    else
            //    {
            //        dgv_so_pack_header.CurrentRow.Cells["standby"].Value = ds_address.Tables[0].Rows[0]["standby_12"].ToString().Trim();
            //    }
            //}         
        }


        private void dgv_so_pack_header_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if ((dgv_so_pack_header.Columns[e.ColumnIndex].Name.Trim() == "net_weight_so_pack_header") && (dgv_so_pack_header.CurrentRow.Cells["net_weight_so_pack_header"].Value.ToString().Trim() != ""))
            {
                ds_address = new DataSet();
                string str_address;
                if (dgv_so_pack_header.CurrentRow != null)
                {
                    str_address = "select top 1 standby_11,standby_12 from " + main.g_space + ".so_ship_header a ," + main.g_space + ".so_pack_header b " +
                                        "where a.inv_org = b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no " +
                                        "and b.inv_org ='" + main.g_org + "' " +
                                        "and b.consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "' " +
                                         "and b.box_no ='" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'";
                    if (main.dbtype == "SQL")
                    {
                        ds_address = main.dbservice.Sql_exec_selectsql(str_address);
                    }
                    else
                    {
                        ds_address = main.dbservice.oracle_exec_selectsql(str_address);
                    }

                }

                if (Convert.ToDouble(dgv_so_pack_header.CurrentRow.Cells["net_weight_so_pack_header"].Value.ToString().Trim()) <= 20)
                {
                    dgv_so_pack_header.CurrentRow.Cells["send_type_so_pack_header"].Value = "0";
                    if (ds_address.Tables[0].Rows.Count > 0)
                        dgv_so_pack_header.CurrentRow.Cells["standby"].Value = ds_address.Tables[0].Rows[0]["standby_11"].ToString().Trim();
                }
                else
                {
                    dgv_so_pack_header.CurrentRow.Cells["send_type_so_pack_header"].Value = "1";
                    if (ds_address.Tables[0].Rows.Count > 0)
                        dgv_so_pack_header.CurrentRow.Cells["standby"].Value = ds_address.Tables[0].Rows[0]["standby_12"].ToString().Trim();
                }
            }

        }


        private void btn_check_load_Click(object sender, EventArgs e)
        {
            int i_count = 0;
            for (int i = 0; i < dgv_so_ship_detail.Rows.Count; i++)
            {
                if (Convert.ToDouble(dgv_so_ship_detail.Rows[i].Cells["unbox_qty"].Value.ToString().Trim()) == 0.0000)
                    i_count++;
            }
            if (i_count < dgv_so_ship_detail.Rows.Count)
            {
                MessageBox.Show("还有物料未装箱!");
                return;
            }
            else
            {
                btn_Query_Click(sender, e);
            }
        }

        private void cmb_type_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.cmb_type.SelectedIndex == 0)
            {
                this.lbl_number.Text = "订单号";
                this.tb_so_type.Enabled = true;
                this.tb_customer_name.Enabled = true;
                this.tb_customer_sale_no.Enabled = true;
                btn_print.Enabled = false;
                btn_detail_print.Enabled = false;
                //if (this.dgv_so_ship_detail.Columns["wave_no_ship_detail"].Visible == true)
                //    this.dgv_so_ship_detail.Columns["wave_no_ship_detail"].Visible = false;
                if (ds_temp_wave.Tables.Count > 0)
                {
                    ds_temp_wave.Tables[0].Rows.Clear();
                }
                if (ds_temp.Tables.Count > 0)
                {
                    ds_temp.Tables[0].Rows.Clear();
                    //this.dgv_so_ship_header.DataSource = ds_temp.Tables[0];
                }
                if (dgv_so_ship_detail.Rows.Count > 0)
                {
                    DataTable dt = new DataTable();
                    //清空so_pack_detail
                    dt = dgv_so_ship_detail.DataSource as DataTable;
                    dt.Rows.Clear();
                    dgv_so_ship_detail.DataSource = dt;
                }
                if (dgv_so_pack_header.Rows.Count > 0)
                {
                    DataTable dt = new DataTable();
                    //清空so_pack_detail
                    dt = dgv_so_pack_header.DataSource as DataTable;
                    dt.Rows.Clear();
                    dgv_so_pack_header.DataSource = dt;
                }
                if (dgv_so_pack_detail.Rows.Count > 0)
                {
                    DataTable dt = new DataTable();
                    //清空so_pack_detail
                    dt = dgv_so_pack_detail.DataSource as DataTable;
                    dt.Rows.Clear();
                    dgv_so_pack_detail.DataSource = dt;
                }
                //if (this.dgv_so_ship_header.Columns["so_no"].Visible != null)
                //    this.dgv_so_ship_header.Columns["so_no"].Visible = true;
                //if(this.dgv_so_ship_header.Columns["customer_sale_no"].Visible != null)
                //    this.dgv_so_ship_header.Columns["customer_sale_no"].Visible = true;
                //if (this.dgv_so_ship_header.Columns["customer_name"].Visible != null)
                //    this.dgv_so_ship_header.Columns["customer_name"].Visible = true;
                //if (this.dgv_so_ship_header.Columns["ship_day"].Visible != null)
                //    this.dgv_so_ship_header.Columns["ship_day"].Visible = true;                
            }
            else
            {
                this.lbl_number.Text = "波次号";
                //if (this.dgv_so_ship_detail.Columns["wave_no_ship_detail"].Visible == false)
                //    this.dgv_so_ship_detail.Columns["wave_no_ship_detail"].Visible = true;
                this.tb_customer_name.Enabled = false;
                this.tb_customer_sale_no.Enabled = false;
                btn_print.Enabled = false;
                btn_detail_print.Enabled = false;
                if (ds_temp_wave.Tables.Count > 0)
                {
                    ds_temp_wave.Tables[0].Rows.Clear();
                    //this.dgv_so_ship_header.DataSource = ds_temp_wave.Tables[0];
                }
                if (ds_temp.Tables.Count > 0)
                {
                    ds_temp.Tables[0].Rows.Clear();
                }
                if (dgv_so_ship_detail.Rows.Count > 0)
                {
                    DataTable dt = new DataTable();    
                    //清空so_pack_detail
                    dt = dgv_so_ship_detail.DataSource as DataTable;
                    dt.Rows.Clear();
                    dgv_so_ship_detail.DataSource = dt;
                }
                if (dgv_so_pack_header.Rows.Count > 0)
                {
                    DataTable dt = new DataTable();
                    //清空so_pack_detail
                    dt = dgv_so_pack_header.DataSource as DataTable;
                    dt.Rows.Clear();
                    dgv_so_pack_header.DataSource = dt;
                }
                if (dgv_so_pack_detail.Rows.Count > 0)    
                {
                    DataTable dt = new DataTable();   
                    //清空so_pack_detail
                    dt = dgv_so_pack_detail.DataSource as DataTable;
                    dt.Rows.Clear();
                    dgv_so_pack_detail.DataSource = dt;
                }
                //this.dgv_so_ship_header.Columns["so_no"].Visible = false;
                //this.dgv_so_ship_header.Columns["customer_sale_no"].Visible = false;
                //this.dgv_so_ship_header.Columns["customer_name"].Visible = false;
                //this.dgv_so_ship_header.Columns["ship_day"].Visible = false;
            }
        }

        private void btn_detail_print_Click(object sender, EventArgs e)
        {
            //int i = dgv_so_pack_header.CurrentRow.Index;
            

            string s_so_no = "";

            for (int j = 0; j < dgv_so_ship_header.Rows.Count; j++)
            {
                if (this.dgv_so_ship_header.Rows[j].Cells[0].EditedFormattedValue.ToString() == "True")
                {
                    s_so_no += "'" + dgv_so_ship_header.Rows[j].Cells["so_no"].Value.ToString().Trim() + "',";
                }
            }
            s_so_no = s_so_no.Substring(0, s_so_no.Length - 1);
            string str_send_no_sql="";
            for (int i = 0; i < dgv_so_pack_header.Rows.Count; i++)
            {
                string box_no_i = "";
                if (i_ds_so_pack_header_s.Tables[0].Rows[i]["net_weight"].ToString().Trim() == "")
                {  
                    MessageBox.Show("请输入箱子的重量并保存！");
                    return;
                }
                if (i_ds_so_pack_header_s.Tables[0].Rows[i]["send_type"].ToString().Trim() == "")    
                {
                    MessageBox.Show("请选择发运方式并保存!");
                    return;
                }
                if ((bool)dgv_so_pack_header.Rows[i].Cells["checkboxHeader"].EditedFormattedValue)
                {
                    box_no_i = dgv_so_pack_header.Rows[i].Cells["box_no_so_pack_header"].Value.ToString();

                    str_send_no_sql += " select '*'+ltrim(rtrim(c.send_no))+'*' send_no,case c.send_type when '0' then a.standby_11 when '1' then a.standby_12 else '' end carrier,a.customer_name,c.address,a.confirm_day ship_day,case ltrim(rtrim(a.address)) when '' then f.clerk else a.receiver end receiver,case ltrim(rtrim(a.address)) when '' then f.telephone else a.telephone end telephone,d.sku,e.attribute5 lot_attribute5,e.sku_name,case a.so_type when '4' then b.standby_3 else a.standby_13 end so_no,d.order_unit,d.ship_qty_m,d.box_no,c.spec,c.box_size,c.net_weight,c.carrier_postalcode as box_number,case ltrim(rtrim(c.carrier_phone)) when '0' then '否' when '1' then '是' else '' end  repack_type,c.maker,Convert(char(10),c.made_time,102) as made_time,Convert(char(10),getdate(),102) as ship_made_time,'系统管理员' as ship_mader " +
                                                    ",c.spec,c.box_size,c.net_weight,'0.0' as box_number,'' as repack_type from " + main.g_space + ".so_ship_header a, " + main.g_space + ".so_ship_detail b, " + main.g_space + ".so_pack_header c, " + main.g_space + ".so_pack_detail d, " + main.g_space + ".mst_sku e," + main.g_space + ".mst_customer f where a.inv_org *= f.inv_org and a.customer_code *= f.consignor and a.customer_name *= f.consignor_name and a.inv_org=b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no and b.inv_org=d.inv_org and b.consignor=d.consignor and b.so_no = d.so_no " +
                                                    "and b.so_line_no = d.so_line_no and b.inv_org = e.inv_org and b.consignor= e.consignor and b.sku = e.sku and c.inv_org=d.inv_org and c.consignor=d.consignor and c.so_no=d.so_no and c.box_no = d.box_no and a.so_status in ('3','4') and a.inv_org = '" + main.g_org + "' and c.box_no ='" + box_no_i + "' and a.so_no in (" + s_so_no + ")   union all ";
                }
            }


            if (str_send_no_sql.Trim() == "") 
            {
                MessageBox.Show("请选择要打印的箱单！");
                return;
            }


                ds_system_send_no = new DataSet();

                    try
                    {

                        if (main.dbtype == "SQL")
                        {
                            str_send_no_sql = str_send_no_sql.Substring(0, str_send_no_sql.Length - 11);
                            ds_system_send_no = main.dbservice.Sql_exec_selectsql(str_send_no_sql);
                        }


                            try
                            {
                                this.so_019_rpt1.SetDataSource(ds_system_send_no.Tables[0]);
                                crystalReportViewer2.ReportSource = so_019_rpt1;
                                if (ds_system_send_no.Tables[0].Rows.Count > 0)
                                    this.btn_detail_print.Enabled = true;
                                else
                                    this.btn_detail_print.Enabled = false;
                            }  
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                                return;
                            }
                      
                    }
                    catch (Exception ee)
                    {
                        MessageBox.Show(ee.Message);
                        return;
                    }




                //if (MessageBox.Show("确定打印?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                //{
                crystalReportViewer2.PrintReport();
                //}
            
            
        }

        private void dgv_so_pack_header_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            if (dgv_so_pack_header.Columns[dgv_so_pack_header.CurrentCell.ColumnIndex].Name.ToString().Trim() == "send_type_so_pack_header")
            {
                if (dgv_so_pack_header.IsCurrentCellDirty)
                {
                    dgv_so_pack_header.CommitEdit(DataGridViewDataErrorContexts.Commit);
                }
            }
        }

        private void dgv_so_pack_header_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            int row_no;
            if (dgv_so_pack_header.CurrentRow != null)
            {
                row_no = e.RowIndex;

                if (row_no >= 0 && dgv_so_pack_header.Columns[e.ColumnIndex].Name.ToString().Trim() == "send_type_so_pack_header")
                {
                    if (dgv_so_pack_header.Columns[e.ColumnIndex].Name.ToString().Trim() == "send_type_so_pack_header")
                    {

                        if (dgv_so_pack_header.CurrentRow != null)
                        {
                            ds_address = new DataSet();
                            string str_address = "select top 1 standby_11,standby_12 from " + main.g_space + ".so_ship_header a ," + main.g_space + ".so_pack_header b " +
                                                "where a.inv_org = b.inv_org and a.consignor = b.consignor and a.so_no = b.so_no " +
                                                "and b.inv_org ='" + main.g_org + "' " +
                                                "and b.consignor ='" + dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim() + "' " +
                                                 "and b.box_no ='" + dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim() + "'";
                            if (main.dbtype == "SQL")
                            {
                                ds_address = main.dbservice.Sql_exec_selectsql(str_address);
                            }
                            else
                            {
                                ds_address = main.dbservice.oracle_exec_selectsql(str_address);
                            }

                        }

                        if (dgv_so_pack_header.CurrentRow.Cells["send_type_so_pack_header"].Value.ToString().Trim() == "0")
                        {
                            dgv_so_pack_header.CurrentRow.Cells["standby"].Value = ds_address.Tables[0].Rows[0]["standby_11"].ToString().Trim();
                        }
                        else if ((dgv_so_pack_header.CurrentRow.Cells["send_type_so_pack_header"].Value.ToString().Trim() == "1"))
                        {
                            dgv_so_pack_header.CurrentRow.Cells["standby"].Value = ds_address.Tables[0].Rows[0]["standby_12"].ToString().Trim();
                        }
                    }
                }
            }

              
        }

        private void dgv_so_pack_header_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {
              
        }

        //响应“虚拟箱”按钮事件
        private void btnVirtualBox_Click(object sender, EventArgs e)
        {
            string str_get_sql, str_box_new;
            string str_box_no, str_consignor, str_so_no, str_so_line_no;
            int i_no; 
            string[] strSql = new string[2];
            btnVirtualBox.Enabled = false;
            if (dgv_so_ship_detail.CurrentRow == null)
            {
                MessageBox.Show("请选择出库单号!");
                btnVirtualBox.Enabled = true;
                return;
            }
            if (dgv_so_pack_header.CurrentRow == null)
            {
                MessageBox.Show("请选择箱号!");
                btnVirtualBox.Enabled = true;
                return;
            }
            if (dgv_so_pack_header.CurrentRow.Cells["standby_1"].Value.ToString().Trim() == "1")
            {
                MessageBox.Show("该箱已是虚拟箱，请重新选择！");
                btnVirtualBox.Enabled = true;
                return;
            }
            else if (dgv_so_pack_header.CurrentRow.Cells["standby_1"].Value.ToString().Trim() == "0")
            {
                //得到当前选中箱号
                str_box_no = dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim();
                str_consignor = dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim();
                str_so_no = dgv_so_ship_detail.CurrentRow.Cells["so_no_ship_detail"].Value.ToString().Trim();
                str_so_line_no = dgv_so_ship_detail.CurrentRow.Cells["so_line_no"].Value.ToString().Trim();
                //判断商品是否已经装箱 
                bool b_find_flag = false;
                for (int i = 0; i < dgv_so_pack_detail.Rows.Count;i++ )
                {
                    if (str_box_no == dgv_so_pack_detail.Rows[i].Cells["box_no_so_pack_detail"].EditedFormattedValue.ToString().Trim() &&
                        str_consignor == dgv_so_pack_detail.Rows[i].Cells["consignor_so_pack_detail"].EditedFormattedValue.ToString().Trim() &&
                        str_so_no == dgv_so_pack_detail.Rows[i].Cells["so_no_so_pack_detail"].EditedFormattedValue.ToString().Trim() &&
                        str_so_line_no == dgv_so_pack_detail.Rows[i].Cells["so_line_no_so_pack_detail"].EditedFormattedValue.ToString().Trim())
                    {
                        b_find_flag = true;
                        break;
                    }

                }
                if(!b_find_flag)
                {
                    MessageBox.Show("商品" + dgv_so_ship_detail.CurrentRow.Cells["sku"].Value.ToString().Trim()+"还没有装箱!");
                    btnVirtualBox.Enabled = true;
                    return;
                }

                try
                {
                    if (main.dbtype == "SQL")
                    {
                        str_get_sql = "select isnull(max(convert(int,substring(box_no,charindex('/',box_no)+1,len(box_no)-" + 
                                "charindex('/',box_no)))),0) + 1 from " + main.g_space + ".so_pack_header where inv_org = '" + main.g_org + "'" +
                                      " and consignor = '" + str_consignor + "' and so_no = '" + str_so_no + "' and box_no like '" + str_box_no.Trim() + "/%'";
                        i_no = main.dbservice.Sql_exec_selectint(str_get_sql);
                        str_box_new = str_box_no.Trim() + "/" + i_no.ToString();
                        //插入数据到so_pack_header表
                        strSql[0] = "insert into " + main.g_space + ".so_pack_header(inv_org,	consignor,	so_no,		box_no," +
                                                                "spec,		box_size,	net_weight,	send_no," +
                                                                "carrier,	carrier_address,	carrier_postalcode,	carrier_phone," +
                                                                "address,	send_type,	ship_no,	fly_no," +
                                                                "vehicle_no,	status,		ship_day,	shipper," +
                                                                "standby_1,	standby_2,	standby_3,	standby_4," +
                                                                "standby_5,	standby_6,	standby_7,	memo," +
                                                                "main_dist,	made_time,	maker)" +
                                                         " select inv_org,	consignor,	so_no,	'" + str_box_new + "'," +
                                                                "spec,		box_size,	0,	send_no," +
                                                                "carrier,	carrier_address,	carrier_postalcode,	carrier_phone," +
                                                                "address,	send_type,	ship_no,	fly_no," +
                                                                "vehicle_no,	status,		ship_day,	shipper," +
                                                                "'1',	standby_2,	standby_3,	standby_4," +
                                                                "standby_5,	standby_6,	standby_7,	memo," +
                                                                "'A',	getdate(),	'" + main.g_user + "'" +
                                                         " from " + main.g_space + ".so_pack_header where  inv_org = '" + main.g_org + "' and consignor = '" + str_consignor + "' and so_no = '" + str_so_no + "' and box_no = '" + str_box_no.Trim() + "'";
                        //插入数据到so_pack_detail表
                        strSql[1] = "insert into " + main.g_space + ".so_pack_detail(inv_org,	consignor, so_no,  box_no," +
                                                                  "so_line_no,	sku,		pack_code,	ship_qty_m," +
                                                                  "ship_qty_s,	order_price,	order_unit,	ship_cubage," +
                                                                  "ship_gross_weight,	ship_net_weight,	main_sub_flag,	convert_modulus," +
                                                                  "lot_attribute1,	lot_attribute2,	lot_attribute3,	lot_attribute4," +
                                                                  "lot_attribute5,	lot_attribute6,	lot_attribute7,	lot_attribute8," +
                                                                  "lot_attribute9,	lot_attribute10,	lot_attribute11,	lot_attribute12," +
                                                                  "lot_attribute13,	lot_attribute14,	lot_attribute15,	standby_1," +
                                                                  "standby_2,	standby_3,	standby_4,	standby_5," +
                                                                  "standby_6,	standby_7,	memo,		main_dist, made_time,	maker)" +
                                                          " select  a.inv_org,	a.consignor, a.so_no, '" + str_box_new + "'," +
                                                                  "a.so_line_no,a.sku, a.pack_code,	0," +
                                                                  "0, a.order_price, a.order_unit,	0," +
                                                                  "0,	0,	a.main_sub_flag,	a.convert_modulus," +
                                                                  "a.lot_attribute1, a.lot_attribute2,	a.lot_attribute3, a.lot_attribute4," +
                                                                  "a.lot_attribute5, a.lot_attribute6,	a.lot_attribute7,	a.lot_attribute8," +
                                                                  "a.lot_attribute9, a.lot_attribute10,	a.lot_attribute11,	a.lot_attribute12," +
                                                                  "a.lot_attribute13, a.lot_attribute14, a.lot_attribute15,	a.standby_1," +
                                                                  "a.standby_2,	a.standby_3, a.standby_4,	a.standby_5," +
                                                                  "a.standby_6,	a.standby_7, b.sku_name+'(附件)','A', getDate(),	'" + main.g_user + "' " +
                                                         " from " + main.g_space + ".so_pack_detail a ," + main.g_space + ".mst_sku b where  a.inv_org = '" + main.g_org + 
                                                         "' and a.consignor = '" + str_consignor + "' and a.so_no = '" + str_so_no + "' and a.so_line_no =" + str_so_line_no + 
                                                         " and a.box_no = '" + str_box_no.Trim() + "' and a.sku = b.sku and a.inv_org = b.inv_org and a.consignor=b.consignor";
                        main.dbservice.Sql_exec_mutilsql(strSql);
                    }
                    else
                    {
                        str_get_sql = "select nvl(max(to_number(Substr(box_no,Instr(box_no,'/')+1,length(box_no)-Instr(box_no,'/')))),0)+1" +
                                        " from " + main.g_space + ".so_pack_header where inv_org = '" + main.g_org + "' and consignor = '" + str_consignor + "' and so_no = '" + str_so_no + "' and box_no like '" + str_box_no.Trim() + "/%'";
                        i_no = main.dbservice.oracle_exec_selectint(str_get_sql);
                        str_box_new = str_box_no.Trim() + "-" + i_no.ToString();
                        //插入数据到so_pack_header表
                        strSql[0] = "insert into " + main.g_space + ".so_pack_header(inv_org,	consignor,	so_no,		box_no," +
                                                                "spec,		box_size,	net_weight,	send_no," +
                                                                "carrier,	carrier_address,	carrier_postalcode,	carrier_phone," +
                                                                "address,	send_type,	ship_no,	fly_no," +
                                                                "vehicle_no,	status,		ship_day,	shipper," +
                                                                "standby_1,	standbstandby_6y_2,	standby_3,	standby_4," +
                                                                "standby_5,	,	standby_7,	memo," +
                                                                "main_dist,	made_time,	maker)" +
                                                         " select inv_org,	consignor,	so_no,	'" + str_box_new + "'," +
                                                                "spec,		box_size,	0,	send_no," +
                                                                "carrier,	carrier_address,	carrier_postalcode,	carrier_phone," +
                                                                "address,	send_type,	ship_no,	fly_no," +
                                                                "vehicle_no,	status,		ship_day,	shipper," +
                                                                "'1',	standby_2,	standby_3,	standby_4," +
                                                                "standby_5,	standby_6,	standby_7,	memo," +
                                                                "'A', sysdate,	'" + main.g_user + "'" +
                                                         " from " + main.g_space + ".so_pack_header where  inv_org = '" + main.g_org + "' and consignor = '" + str_consignor + "' and so_no = '" + str_so_no + "' and box_no = '" + str_box_no.Trim() + "'";
                        //插入数据到so_pack_detail表
                        strSql[1] = "insert into " + main.g_space + ".so_pack_detail(inv_org,	consignor, so_no,  box_no," +
                                                                            "so_line_no,	sku,		pack_code,	ship_qty_m," +
                                                                            "ship_qty_s,	order_price,	order_unit,	ship_cubage," +
                                                                            "ship_gross_weight,	ship_net_weight,	main_sub_flag,	convert_modulus," +
                                                                            "lot_attribute1,	lot_attribute2,	lot_attribute3,	lot_attribute4," +
                                                                            "lot_attribute5,	lot_attribute6,	lot_attribute7,	lot_attribute8," +
                                                                            "lot_attribute9,	lot_attribute10,	lot_attribute11,	lot_attribute12," +
                                                                            "lot_attribute13,	lot_attribute14,	lot_attribute15,	standby_1," +
                                                                            "standby_2,	standby_3,	standby_4,	standby_5," +
                                                                            "standby_6,	standby_7,	memo,		main_dist, made_time,	maker)" +
                                                                    " select  a.inv_org,	a.consignor, a.so_no, '" + str_box_new + "'," +
                                                                            "a.so_line_no,a.sku, a.pack_code,	0," +
                                                                            "0, a.order_price, a.order_unit,	0," +
                                                                            "0,	0,	a.main_sub_flag,	a.convert_modulus," +
                                                                            "a.lot_attribute1, a.lot_attribute2,	a.lot_attribute3, a.lot_attribute4," +
                                                                            "a.lot_attribute5, a.lot_attribute6,	a.lot_attribute7,	a.lot_attribute8," +
                                                                            "a.lot_attribute9, a.lot_attribute10,	a.lot_attribute11,	a.lot_attribute12," +
                                                                            "a.lot_attribute13, a.lot_attribute14, a.lot_attribute15,	a.standby_1," +
                                                                            "a.standby_2,	a.standby_3, a.standby_4,	a.standby_5," +
                                                                            "a.standby_6,	a.standby_7, b.sku_name||'(附件)','A', sysdate,	'" + main.g_user + "' " +
                                                                   " from " + main.g_space + ".so_pack_detail a ," + main.g_space + ".mst_sku b where  a.inv_org = '" + main.g_org +
                                                                   "' and a.consignor = '" + str_consignor + "' and a.so_no = '" + str_so_no + "' and a.so_line_no =" + str_so_line_no +
                                                                   " and a.box_no = '" + str_box_no.Trim() + "' and a.sku = b.sku and a.inv_org = b.inv_org and a.consignor=b.consignor";
                        main.dbservice.oracle_exec_mutilsql(strSql);
                    }
                    //刷新数据
                    f_refresh_virtule_box(str_consignor, str_so_no);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                    btnVirtualBox.Enabled = true;
                    return;
                }
            }
            btnVirtualBox.Enabled = true;
        }

        private void 复制装箱ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dgv_so_pack_header.Rows.Count == 0) return;
            

            w_so019_copy copy = new w_so019_copy();
            //copy.Show(this);
            if (copy.ShowDialog(this) == DialogResult.OK)
            {
               
                if (w_so019_copy.count == "") return;

                try
                {
                    for (int i = 0; i < dgv_so_pack_detail.Rows.Count; i++)
                    {
                        if (dgv_so_pack_detail.Rows[i].Cells["box_no_so_pack_detail"].Value.ToString().Trim() == dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim())
                        {
                            for (int j = 0; j < dgv_so_ship_detail.Rows.Count; j++)
                            {
                                if (dgv_so_ship_detail.Rows[j].Cells["sku"].Value.ToString().Trim() == dgv_so_pack_detail.Rows[i].Cells["sku_so_pack_detail"].Value.ToString().Trim() && dgv_so_ship_detail.Rows[j].Cells["so_line_no"].Value.ToString().Trim() == dgv_so_pack_detail.Rows[i].Cells["so_line_no_so_pack_detail"].Value.ToString().Trim())
                                {
                                    if (Convert.ToDouble(dgv_so_ship_detail.Rows[j].Cells["unbox_qty"].Value.ToString()) / Convert.ToDouble(dgv_so_pack_detail.Rows[i].Cells["ship_qty_m_so_pack_detail"].Value.ToString()) < Convert.ToDouble(w_so019_copy.count))
                                    {
                                        MessageBox.Show("箱子太多，商品不够分配！");
                                        return;
                                    }
                                }
                            }
                        }
                    }  


                    string inv_org_i = dgv_so_pack_header.CurrentRow.Cells["inv_org_so_pack_header"].Value.ToString().Trim();
                    string consignor_i = dgv_so_pack_header.CurrentRow.Cells["consignor_so_pack_header"].Value.ToString().Trim();
                    string box_no_i = dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim();
                    string send_no_i = dgv_so_pack_header.CurrentRow.Cells["send_no_so_pack_header"].Value.ToString().Trim();
                    string str_lod_boxno = "";
                    int box_no_index = Convert.ToInt32(dgv_so_pack_header.CurrentRow.Cells["box_no_so_pack_header"].Value.ToString().Trim().Split('-')[1]);
                    string str_sql = "select max(box_no) from "+main.g_space+".so_pack_header where inv_org='" + main.g_org + "' and consignor='" + consignor_i + "' and send_no='" + send_no_i + "' ";
                    if (main.dbtype == "SQL")
                    {
                        str_lod_boxno = main.dbservice.Sql_exec_selectstring(str_sql);
                    }
                    else
                    {
                        str_lod_boxno = main.dbservice.oracle_exec_selectstring(str_sql);
                    }
                    //string index = Convert.ToString(++box_no_index).PadLeft(3, '0');
                    string index = "";
                    int i_line = 0;
                    if (str_lod_boxno.Trim() != "")
                    {
                        index = str_lod_boxno.Trim().Substring(str_lod_boxno.Trim().Length-3,3);
                        i_line = Convert.ToInt32(index);
                    }
                    
                    for (int i = 0; i < Convert.ToInt32(w_so019_copy.count); i++)
                    {
                        index = Convert.ToString(++i_line).PadLeft(3, '0');
                        if (main.dbtype == "SQL")   
                        {
                            string inPHeaderSql = "insert into " + main.g_space + ".so_pack_header (inv_org,consignor,so_no,box_no,spec,box_size,net_weight,send_no,carrier,carrier_address,carrier_postalcode,carrier_phone,address," +
                                               "send_type,ship_no,fly_no,vehicle_no,status,ship_day,shipper,standby_1,standby_2,standby_3,standby_4,standby_5,standby_6,standby_7,memo,main_dist,made_time,maker,update_time,updater) " +
                                               "select inv_org,consignor,so_no,'" + send_no_i + "-" + index + "',spec,box_size,net_weight,send_no,carrier,carrier_address,carrier_postalcode,carrier_phone,address," +
                                               "send_type,ship_no,fly_no,vehicle_no,status,ship_day,shipper,standby_1,standby_2,standby_3,standby_4,standby_5,standby_6,standby_7,memo,main_dist,made_time,maker,update_time,updater from " + main.g_space + "." +
                                               "so_pack_header where inv_org = '" + inv_org_i + "' and consignor ='" + consignor_i + "' and box_no ='" + box_no_i + "' ";
                            string inDetailSql = "insert into " + main.g_space + ".so_pack_detail (inv_org,consignor,so_no,box_no,so_line_no,sku,pack_code,ship_qty_m,ship_qty_s,order_price,order_unit,ship_cubage,ship_gross_weight,ship_net_weight,main_sub_flag,main_dist,made_time,maker,update_time,updater) " +
                                                "select inv_org,consignor,so_no,'" + send_no_i + "-" + index + "',so_line_no,sku,pack_code,ship_qty_m,ship_qty_s,order_price,order_unit,ship_cubage,ship_gross_weight ,ship_net_weight,main_sub_flag,main_dist,made_time,maker,update_time,updater " +
                                                "from " + main.g_space + ".so_pack_detail where inv_org = '" + inv_org_i + "' and consignor ='" + consignor_i + "' and box_no ='" + box_no_i + "' ";

                            try  
                            {
                                main.dbservice.Sql_exec_commandsql(inPHeaderSql);
                                main.dbservice.Sql_exec_commandsql(inDetailSql);
                                so_bind();
                            }
                            catch (Exception ee)
                            {
                                MessageBox.Show(ee.ToString());
                                return;
                            }
                        }
                    }
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(ee.Message);
                }


            }
        }
        
    }
}